Public Function FormatBytes(ByVal bytes As Long) As String Dim units As String() = {"B", "KB", "MB", "GB"} Dim i As Integer = 0 Dim retval As Double = bytes While retval >= 1024 AndAlso i < units.Length - 1 retval /= 1024 i += 1 End While Return String.Format("{0:F2}{1}", retval, units(i)) End Function