Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1563 | Anzahl registrierter User: 1896 | Besucher online: 5
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Umrechnung von Byte bis Yottabyte


Autor: Volker Steitz
Sprache: VB.NET
Bewertung:
8.69 (3 votes)
Anzahl der Aufrufe: 5613
  
Kick it on dotnet-kicks.de  

Beschreibung:

Braucht man eine Function die von Bytes bis Yottabyte alles sauber zurückliefert, leistet das folgende Snippet nette Dienste

Abgelegt unter: byte, Umrechnung, Format Bytes.



Visual Basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    ''' <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")
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.