Braucht man eine Function die von Bytes bis Yottabyte alles sauber zurückliefert, leistet das folgende Snippet nette Dienste
''' <summary>
''' Bytes Formatiert nach KB, MB, GB, etc. ausgeben
'''
''' Kilobyte (kB) = 1024 Byte
''' Megabyte (MB) = 1.048.576 Byte
''' Gigabyte (GB) = 1.073.741.824 Byte
''' Terabyte (TB) = 1.099.511.627.776 Byte
''' Petabyte (PB) = 1.125.899.906.842.624 Byte
''' Exabyte (EB) = 1.152.921.504.606.846.976 Byte
''' Zettabyte (ZB) = 1.180.591.620.717.411.303.424 Byte
''' Yottabyte (YB) = 1.208.925.819.614.629.174.706.176 Byte
'''
''' </summary>
''' <param name="dblbytes"></param>
''' <param name="strFormated"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function FormatBytes(ByVal dblbytes As Double, ByVal strFormated As String) As String
Dim arrPosForm() As String = {"Bytes", "Kilobyte", "Megabyte", "Gigabyte", _
"Terabyte", "Petabyte", "Exabyte", "Zettabyte", "Yottabyte"}
For i As Integer = arrPosForm.Length - 1 To 0 Step -1
If dblbytes > 1024 ^ i Then
dblbytes /= 1024 ^ i
Return dblbytes.ToString(strFormated) & " " & _
arrPosForm(i)
End If
Next i
Return dblbytes.ToString(strFormated) & " Bytes"
End Function
'Aufruf:
FormatBytes(Me.TextBox2.Text, "0.00")
Kommentare zum Snippet