Advertisement
7_2009-2012 String Manipulation #217371

FormatFileSize

FormatFileSize: Formats a file's size in bytes into X GB or X MB or X KB or X bytes depending on size (a la Win9x Properties tab) * UPDATED Sept. 12, 2000 * to allow for overriding the default Format Mask.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
Public Function FormatFileSize(ByVal dblFileSize As Double, _
                Optional ByVal strFormatMask As String) _
                As String
' FormatFileSize:  Formats dblFileSize in bytes into
'          X GB or X MB or X KB or X bytes depending
'          on size (a la Win9x Properties tab)
Select Case dblFileSize
  Case 0 To 1023       ' Bytes
    FormatFileSize = Format(dblFileSize) & " bytes"
  Case 1024 To 1048575    ' KB
    If strFormatMask = Empty Then strFormatMask = "###0"
    FormatFileSize = Format(dblFileSize / 1024#, strFormatMask) & " KB"
  Case 1024# ^ 2 To 1073741823 ' MB
    If strFormatMask = Empty Then strFormatMask = "###0.0"
    FormatFileSize = Format(dblFileSize / (1024# ^ 2), strFormatMask) & " MB"
  Case Is > 1073741823#    ' GB
    If strFormatMask = Empty Then strFormatMask = "###0.0"
    FormatFileSize = Format(dblFileSize / (1024# ^ 3), strFormatMask) & " GB"
End Select
End Function

Původní komentáře (3)
Obnoveno z Wayback Machine