バイトサイズを表す数値を文字列に変換          <TOP>


StrFormatByteSize バイトサイズを表す数値を文字列に変換します。

 

 

'================================================================
'= バイトサイズを表す数値を文字列に変換
'=    (StrFormatByteSize.bas)
'================================================================

' バイトサイズを表す数値を文字列に変換
Declare Function Api_StrFormatByteSize& Lib "shlwapi" Alias "StrFormatByteSizeA" (ByVal dw&, ByVal pszBuf$, ByVal cchBuf&)

'================================================================
'= 
'================================================================
Declare Function FormatByteSize(dwBytes As Single) As String
Function FormatByteSize(dwBytes As Single) As String
    Var Buff As String
    Var dwBuff As Long

    Buff = Space$(32)
    dwBuff = Len(Buff)

    If Api_StrFormatByteSize(dwBytes, Buff, dwBuff) <> 0 Then
        FormatByteSize = Left$(Buff, InStr(Buff, Chr$(0)) - 1)
    End If
End Function

'------------------------------
Print format$(2147483147 , "###,###,###,###.## ") & FormatByteSize(2147483147)
Print format$(37423218.34, "###,###,###,###.## ") & FormatByteSize(37423218.34)
Print format$(3742321.34 , "###,###,###,###.## ") & FormatByteSize(3742321.34)
Print format$(374232.34  , "###,###,###,###.## ") & FormatByteSize(374232.34)
Print format$(37423.34   , "###,###,###,###.## ") & FormatByteSize(37423.34)
Print format$(3742.34    , "###,###,###,###.## ") & FormatByteSize(3742.34)
Print format$(1024       , "###,###,###,###.## ") & FormatByteSize(1024)
Print format$(1023       , "###,###,###,###.## ") & FormatByteSize(1023)
Print format$(374.34     , "###,###,###,###.## ") & FormatByteSize(374.34)
Print format$(37.34      , "###,###,###,###.## ") & FormatByteSize(37.34)

Stop
End