Programming » Visual Basic 6 » Visual Basic 6 Code » Strings » ");?>
Formats a number of bytes to display in KB, MB or GB depending on size.
Private Declare Function StrFormatByteSize Lib _
        "shlwapi" Alias "StrFormatByteSizeA" (ByVal _
        dw As LongByVal pszBuf As StringByRef _
        cchBuf As LongAs String

Private Function FormatKB(ByVal Amount As LongAs String
    Dim Buffer As String
    Dim Result As String

    Buffer = Space$(255)
    Result = StrFormatByteSize(Amount, Buffer, Len(Buffer))

    If InStr(Result, vbNullChar) > 1 Then
        FormatKB = Left$(Result, InStr(Result, vbNullChar) - 1)
    End If
End Function