Pastetool - FormatFileSize

URL: , Paste another

Function FormatFileSize(Size As Double) As String
    Dim PreFix$
    Dim Suffixes(1 To 6) As String
    Suffixes(1) = " bytes"
    Suffixes(2) = " KB"
    Suffixes(3) = " MB"
    Suffixes(4) = " GB"
    Suffixes(5) = " TB"

    Dim i As Integer
    i = ((Len(CStr(Size)) - 1) \ 3)
    PreFix = Size / Val(1 & String$(i * 3, "0"))
    PreFix = Format$(PreFix, "###.##")
    PreFix = Val(PreFix)
    
    If i >= UBound(Suffixes) Then
        FormatFileSize = PreFix & Suffixes(UBound(Suffixes) - 1)
    Else
        FormatFileSize = PreFix & Suffixes(i + 1)
    End If
End Function

Download code

This visual basic code was pasted on September 8, 2009




Protected with advance Anti-SPAM techniques :)
Coded and designed by Fedmich
Follow us on Twitter