|
Convert Bytes to the Appropriate Format (Bytes, KB, MB, GB)
| Version Compatibility: |
Visual Basic 5 Visual Basic 6
|
More information: Convert bytes to the best format (Bytes, KB, MB, GB)
Examples:
- SetBytes(74) 'returns "74 Bytes"
- SetBytes(5037) 'returns "4.92 KB"
- SetBytes(6383838) 'returns "6.09 MB"
- SetBytes(3368383278) 'returns "3.14 GB"
This code has been viewed 336167 times. Instructions: Copy the declarations and code below and paste directly into your VB project. Declarations:
'none Code:
Function SetBytes(Bytes) As String
On Error GoTo hell
If Bytes >= 1073741824 Then
SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") _
& " GB"
ElseIf Bytes >= 1048576 Then
SetBytes = Format(Bytes / 1024 / 1024, "#0.00") & " MB"
ElseIf Bytes >= 1024 Then
SetBytes = Format(Bytes / 1024, "#0.00") & " KB"
ElseIf Bytes < 1024 Then
SetBytes = Fix(Bytes) & " Bytes"
End If
Exit Function
hell:
SetBytes = "0 Bytes"
End Function
Text Boxes
|