Convert File Size to Different Size Units
Posted by admin - Mar 31, 2008 Articles, Dani Vainstein, Files, QTips 0 0 Views : 227 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 16, 2011
Public Sub FileSizeStrings( ByVal fileSize, ByRef sizes )
Const K_SIZE = 1024
Set sizes = CreateObject( "Scripting.Dictionary" )
fileSize = CDbl( fileSize )
sizes.Add "Bytes", Cstr( fileSize )
tmpSize = CDbl( fileSize / K_SIZE )
sizes.Add "KB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "MB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "GB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "TB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "PB", Cstr( tmpSize )
End Sub
This nice function will convert a size string to a size string representation in various units. the ByRef sizes parameter is converted to a Dictionary in the Sub. then a calculation is performed for every unit offsets of 1K.
Call FileSizeStrings( "5000000000", sizes )
For Each key In sizes.Keys
Print sizes( key ) & " " & key
Next
The output would be :


