by Alexandre Bianco (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 18th March 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Convert Bytes into K, MB, GB
Dim nBytes
Dim nBytes2
Dim nBytesConverted
nBytes = Val(cBytes / 1024)
nBytes2 = Val(nBytes / 1024)
Select Case Len(cBytes)
Case 1, 2, 3
'BYTES
nBytesConverted = cBytes & " Bytes"
Case 4, 5, 6
'KILO BYTES
nBytesConverted = Format((cBytes / 1024), "0.00 K")
Case Else
If Len(nBytes2) <= 3 Then
'MEGA BYTES
nBytesConverted = Format((nBytes2), "0 MB")
Else
'GIGA BYTES
nBytesConverted = Format((nBytes2 / 1024), "0.00 GB")
End If
End Select
ConvertBytes = nBytesConverted
End Function