Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 19, 2019 1:17 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Formatted File Size
PostPosted: Sun Jan 31, 2010 5:04 pm 
Offline

Joined: Tue Aug 01, 2006 10:25 pm
Posts: 3
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."


Top
 Profile  
Reply with quote  
 Post subject: Re: Formatted File Size
PostPosted: Sun Jun 26, 2011 1:31 pm 
Offline
User avatar

Joined: Sat May 27, 2006 3:27 pm
Posts: 480
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group