Real Software Forums
http://forums.realsoftware.com/

Formatted File Size
http://forums.realsoftware.com/viewtopic.php?f=21&t=32279
Page 1 of 1

Author:  Mutor [ Sun Jan 31, 2010 5:04 pm ]
Post subject:  Formatted File Size

A method to convert literal file size, returns formatted string
Function FmtSz(int As Double) As String
dim s,units() as string
dim x as integer = 0
units = Array("","K","M","G","T","P")
while int > 1024
int=int/1024
x = x+1
wend
return Format(int,"#,###.##")+" "+units(x)+"B."

Author:  sinner [ Sun Jun 26, 2011 1:31 pm ]
Post subject:  Re: Formatted File Size

Here is another way you can convert a filesize so you can use numbers or strings :P

Sub BytesToString( Bytes As Variant ) As String
If Bytes > Pow( 1024 , 3 ) Then
Return str( Round( Bytes/Pow( 1024 , 3 )*100) /100 ) + " GB"
ElseIf Bytes > 1024*1024 Then
Return Str( Round( Bytes/Pow( 1024 , 2 )*100 ) /100 ) + " MB"
ElseIf Bytes > 1024 Then
Return Str( Round( Bytes/1024*100 ) /100 ) + " KB"
Else
Return Str( Bytes ) + " Bytes"
End
End Sub


Sub Function GetSize( in As Integer ) As String
if (in >= 0) and (in < 1000) then
return str(in) + " bytes"
elseif (in >= 1000) and (in < 1000000) then
return format(in\1000, "#.#") + " KB"
elseif (in >= 1000000) and (in < 1000000000) then
return format(in\1000000, "#.#") + " MB"
elseif (in >= 1000000000) and (in < 1000000000000) then
return format(in\1000000000, "#.#") + " GB"
else
return format(in\1000000000000, "#.#") + " TB"
end if
End Sub

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/