WEICHBRODT.it
Home » wHow? » VB.net » Formattare la dimensione in Byte, KB, MB, GB

Formattare la dimensione in Byte, KB, MB, GB

The WEICHBRODT.it's How-To Directory

Categoria: VB.NET

Descrizione

Questa funzione formatta il valore (double) passato come argomento nel più appropriato in Byte, KB, MB o GB (string).

Codice

Function FormattaDimensione(ByVal DimensioneInBytes As Double) As String

      ' Ritorna una stringa formattata che mostra il valore passato
      ' come argomento nell'equivalente in Bytes, KBytes, MBytes o GBytes
      '
      ' Utilizzo: FormattaDimensione(10000) --> 9,77 KB

      If DimensioneInBytes < 0 Then
         Return DimensioneInBytes.ToString
      ElseIf DimensioneInBytes < 1024 Then
         Return String.Format("{0:N0} B", DimensioneInBytes)
      ElseIf DimensioneInBytes < 1048576 Then
         Return String.Format("{0:N2} KB", DimensioneInBytes / 1024)
      ElseIf DimensioneInBytes < 1073741824 Then
         Return String.Format("{0:N2} MB", DimensioneInBytes / 1048576)
      Else
         Return String.Format("{0:N2} GB", DimensioneInBytes / 1073741824)
      End If

End Function

Commenti

Non ci sono commenti per questa pagina. Vuoi essere il primo a postare un commento?

Scrivi un commento

Nome
Email (non verrà pubblicato)
Web (opzionale)
Inviami una notifica quando un nuovo commento viene aggiunto a questa pagina
Commento
  This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
Inserisci i caratteri di controllo
 

Segnala questa pagina:

Email facebook twitter LinkedIn Tumblr technorati.com del.icio.us FriendFeed digg
Print This Page
Torna su
| Contatti | Mappa | Link |
© WEICHBRODT.it - Grafica, layout e contenuti sono di esclusiva proprietà di Andrea Weichbrodt