1. Este site usa cookies. Ao continuar a usar este site está a concordar com o nosso uso de cookies. Saber Mais.

Conversor de memoria VB/VB.NET

Discussão em 'Programação' iniciada por fLaSh_CF, 11 de Outubro de 2008. (Respostas: 0; Visualizações: 1719)

  1. fLaSh_CF

    fLaSh_CF Banido

    Copyright: <podem por vosso nome, não "rego" pragas :)>

    VB.NET
    Código:
        Public Function FormatBytes(ByVal dblBytes As Double) As String
            Const KILOBYTE As Double = 1024
            Const MEGABYTE As Double = KILOBYTE ^ 2
            Const GIGABYTE As Double = KILOBYTE ^ 3
            Const TERABYTE As Double = KILOBYTE ^ 4
            Const PETABYTE As Double = KILOBYTE ^ 5
     
            Select Case dblBytes
                Case Is >= PETABYTE
                    Return System.Math.Round(dblBytes / PETABYTE, 2) & " PiB"
                Case Is >= TERABYTE
                    Return System.Math.Round(dblBytes / TERABYTE, 2) & " TiB"
                Case Is >= GIGABYTE
                    Return System.Math.Round(dblBytes / GIGABYTE, 2) & " GiB"
                Case Is >= MEGABYTE
                    Return System.Math.Round(dblBytes / MEGABYTE, 2) & " MiB"
                Case Is >= KILOBYTE
                    Return System.Math.Round(dblBytes / KILOBYTE, 2) & " KiB"
                Case Else
                    Return dblBytes & " B"
            End Select
        End Function
    VB6
    Código:
        Public Function FormatBytes(ByVal dblBytes As Double) As String
            Const KILOBYTE As Double = 1024
            Const MEGABYTE As Double = KILOBYTE ^ 2
            Const GIGABYTE As Double = KILOBYTE ^ 3
            Const TERABYTE As Double = KILOBYTE ^ 4
            Const PETABYTE As Double = KILOBYTE ^ 5
     
            Select Case dblBytes
                Case Is >= PETABYTE
                    FormatBytes = Round(dblBytes / PETABYTE, 2) & " PiB"
                Case Is >= TERABYTE
                    FormatBytes = Round(dblBytes / TERABYTE, 2) & " TiB"
                Case Is >= GIGABYTE
                    FormatBytes = Round(dblBytes / GIGABYTE, 2) & " GiB"
                Case Is >= MEGABYTE
                    FormatBytes = Round(dblBytes / MEGABYTE, 2) & " MiB"
                Case Is >= KILOBYTE
                    FormatBytes = Round(dblBytes / KILOBYTE, 2) & " KiB"
                Case Else
                    FormatBytes = dblBytes & " B"
            End Select
        End Function
    Enjoy!

    PS: adicionem ao repositorio :)
     
    Última edição: 11 de Outubro de 2008

Partilhar esta Página