[thelist] ASP/VBScript Byte conversion

Pringle, Ron RPringle at aurora-il.org
Thu Jul 21 16:30:23 CDT 2005


> > I'm using the ASP File Object to return the size of a PDF in 
> > bytes. I want
> > to convert and display the size in MB/KB/Bytes, depending 
> on the size.
> 
> Are you talking about the mathematical conversion, just 
> dividing by 1024
> from bytes to kilobytes, the same from kilobytes to megabytes? Or are
> you looking for more than that?
> 
> joel

Joel-

Mathematical conversion. I think I solved my own problem though. This code
seems to be working:

<%
Function SetBytes(Bytes)

If Bytes >= 1073741824 Then
	SetBytes = Round(FormatNumber(Bytes / 1024 / 1024 / 1024, 2), 0) & "
GB"
ElseIf Bytes >= 1048576 Then
	SetBytes = Round(FormatNumber(Bytes / 1024 / 1024, 2), 0) & " MB"
ElseIf Bytes >= 1024 Then
	SetBytes = Round(FormatNumber(Bytes / 1024, 2), 0) & " KB"
ElseIf Bytes < 1024 Then
	SetBytes = Bytes & " Bytes"
Else
	SetBytes = "0 Bytes"
End If

End Function
%>

Ron


More information about the thelist mailing list