Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function StrFormatByteSize Lib "shlwapi" _
Alias "StrFormatByteSizeA" _
(ByVal dw As Long, _
ByVal pszBuf As String, _
ByVal cchBuf As Long) As Long
Private Sub Command1_Click()
'note: the IN value of the API is a long
Print FormatByteSize(2147483147)
Print FormatByteSize(37423218.34)
Print FormatByteSize(3742321.34)
Print FormatByteSize(374232.34)
Print FormatByteSize(37423.34)
Print FormatByteSize(3742.34)
Print FormatByteSize(1024)
Print FormatByteSize(1023)
Print FormatByteSize(374.34)
Print FormatByteSize(37.34)
End Sub
Private Function FormatByteSize(dwBytes As Single) As String
Dim sBuff As String
Dim dwBuff As Long
sBuff = Space$(32)
dwBuff = Len(sBuff)
If StrFormatByteSize(dwBytes, _
sBuff, _
dwBuff) <> 0 Then
FormatByteSize = Left$(sBuff, _
InStr(sBuff, _
Chr$(0)) - 1)
End If
End Function
|