Código fuente de 'Convierte de bytes a Xbytes.asp'
<html>
<head>
<title>Convierte de bytes a Xbytes - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
</head>
<p align="center"><b><font size="3">Convierte de bytes a Xbytes</font></b>
<body style="font-family: Arial; font-size: 11pt">
</p>
Este código permite la conversión entre bytes y unidades superiores, tales como
kilobytes (kb), megabytes (mb), gigabytes (gb) o terabytes (tb).
<!--
' Name: Convert Bytes
' By: Lewis Moten
' http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6264&lngWId=4
-->
<form method="POST" action="Convierte%20de%20bytes%20a%20Xbytes.asp">
<p>Entra el número en bytes: <input type="text" name="numero" size="20">
<input type="submit" value="Enviar" name="B1"><input type="reset" value="Restablecer" name="B2"></p>
</form>
<%
function ConvertBytes(ByRef anBytes)
Dim lnSize ' File Size To be returned
Dim lsType ' Type of measurement (Bytes, KB, MB, GB, TB)
Const lnBYTE = 1
Const lnKILO = 1024 ' 2^10
Const lnMEGA = 1048576 ' 2^20
Const lnGIGA = 1073741824 ' 2^30
Const lnTERA = 1099511627776 ' 2^40
' Const lnPETA = 1.12589990684262E+15 ' 2^50
' Const lnEXA = 1.15292150460685E+18 ' 2^60
' Const lnZETTA = 1.18059162071741E+21 ' 2^70
' Const lnYOTTA = 1.20892581961463E+24 ' 2^80
if anBytes = "" Or Not IsNumeric(anBytes) Then Exit function
if anBytes < 0 Then Exit function
' If anBytes < lnKILO Then
' ' ByteConversion
' lnSize = anBytes
' lsType = "bytes"
' Else
if anBytes < lnMEGA Then
' KiloByte Conversion
lnSize = (anBytes / lnKILO)
lsType = "kb"
ElseIf anBytes < lnGIGA Then
' MegaByte Conversion
lnSize = (anBytes / lnMEGA)
lsType = "mb"
ElseIf anBytes < lnTERA Then
' GigaByte Conversion
lnSize = (anBytes / lnGIGA)
lsType = "gb"
Else
' TeraByte Conversion
lnSize = (anBytes / lnTERA)
lsType = "tb"
End if
' End If
' Remove fraction
'lnSize = CLng(lnSize)
lnSize = FormatNumber(lnSize, 2, True, False, True)
' Return the results
ConvertBytes = lnSize & " " & lsType
End function
numero=request("numero")
if numero<>"" then
if isnumeric(numero) and numero<>"" then
response.write formatnumber(numero,2) & " bytes son: " & Convertbytes(cdbl(numero))
else
response.write "Formato incorrecto"
end if
end if
%>
</body></html>