Public Class MainClass
Public Shared Function ConvertBytes(ByVal Bytes As Long) As String
If Bytes >= 1073741824 Then
Return Format(Bytes / 1024 / 1024 / 1024, "#0.00") & " GB"
ElseIf Bytes >= 1048576 Then
Return Format(Bytes / 1024 / 1024, "#0.00") & " MB"
ElseIf Bytes >= 1024 Then
Return Format(Bytes / 1024, "#0.00") & " KB"
ElseIf Bytes > 0 And Bytes < 1024 Then
Return Fix(Bytes) & " Bytes"
Else
Return "0 Bytes"
End If
End Function
Public Shared Sub Main()
Dim objInfo As New System.IO.FileInfo("c:\a.dat")
System.Console.WriteLine(ConvertBytes(objInfo.Length))
End Sub
End Class
|