Click here to Skip to main content
15,899,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Filesize Conversion Pin
Dayekh5-May-10 6:16
Dayekh5-May-10 6:16 
GeneralRe: Filesize Conversion Pin
The Man from U.N.C.L.E.5-May-10 6:39
The Man from U.N.C.L.E.5-May-10 6:39 
GeneralRe: Filesize Conversion Pin
Dayekh5-May-10 6:45
Dayekh5-May-10 6:45 
GeneralRe: Filesize Conversion Pin
riced5-May-10 8:34
riced5-May-10 8:34 
GeneralRe: Filesize Conversion Pin
Luc Pattyn5-May-10 8:37
sitebuilderLuc Pattyn5-May-10 8:37 
GeneralRe: Filesize Conversion Pin
riced5-May-10 9:54
riced5-May-10 9:54 
GeneralRe: Filesize Conversion Pin
Luc Pattyn5-May-10 10:33
sitebuilderLuc Pattyn5-May-10 10:33 
GeneralRe: Filesize Conversion Pin
riced5-May-10 10:49
riced5-May-10 10:49 
I decide to benefit and wrote something that does work. Big Grin | :-D
Try plugging yours into the Main and see what happens. Smile | :)
Module Module1
   Sub Main()
      Dim s As String = ""
      Console.WriteLine("--- Kilobytes ---")
      s = FormattedFileSize(1023)
      Console.WriteLine("1023 > " & s)
      s = FormattedFileSize(1024)
      Console.WriteLine("1024 > " & s)
      s = FormattedFileSize(1025)
      Console.WriteLine("1025 > " & s)

      Console.WriteLine("--- Megabytes ---")
      s = FormattedFileSize(1048575)
      Console.WriteLine("1048575 > " & s)
      s = FormattedFileSize(1048576)
      Console.WriteLine("1048576 > " & s)
      s = FormattedFileSize(1048577)
      Console.WriteLine("1048577 > " & s)
      s = FormattedFileSize(1048576 * 2)
      Console.WriteLine("1048577 * 2 > " & s)

      Console.WriteLine("--- Gigabytes ---")
      s = FormattedFileSize(1048576 * 1024)
      Console.WriteLine("1048576 * 1024 > " & s)

      Console.ReadLine()
   End Sub

   Public Function FormattedFileSize(ByVal sizeInBytes As Long) As String
      Dim suffix() As String = New String() {"", "KB", "MB", "GB", "XX"}
      Dim retVal As String = "Oops"
      Dim units As Double = sizeInBytes
      Dim index As Integer = 0
      Do
         units = units / 1024.0
         index += 1
      Loop While units >= 1024.0

      retVal = Format(units, "###,###,##0.000") + suffix(index)
      Return retVal
   End Function

End Module

PS you just need to change the name of the function calls e.g. use s = BytesFormatting(1024)
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.

GeneralRe: Filesize Conversion Pin
Luc Pattyn5-May-10 12:20
sitebuilderLuc Pattyn5-May-10 12:20 
GeneralRe: Filesize Conversion Pin
riced5-May-10 22:09
riced5-May-10 22:09 
GeneralRe: Filesize Conversion Pin
Dayekh5-May-10 12:06
Dayekh5-May-10 12:06 
QuestionWeb Service Problems Pin
RobThompson5-May-10 0:25
RobThompson5-May-10 0:25 
AnswerRe: Web Service Problems Pin
Wayne Gaylard5-May-10 2:21
professionalWayne Gaylard5-May-10 2:21 
AnswerRe: Web Service Problems Pin
Dave Kreskowiak5-May-10 4:16
mveDave Kreskowiak5-May-10 4:16 
QuestionConvert into Char Pin
Anubhava Dimri4-May-10 19:11
Anubhava Dimri4-May-10 19:11 
AnswerRe: Convert into Char Pin
Richard MacCutchan4-May-10 21:39
mveRichard MacCutchan4-May-10 21:39 
GeneralRe: Convert into Char Pin
Anubhava Dimri4-May-10 21:57
Anubhava Dimri4-May-10 21:57 
GeneralRe: Convert into Char Pin
Richard MacCutchan4-May-10 22:09
mveRichard MacCutchan4-May-10 22:09 
GeneralRe: Convert into Char Pin
Anubhava Dimri4-May-10 22:22
Anubhava Dimri4-May-10 22:22 
GeneralRe: Convert into Char Pin
The Man from U.N.C.L.E.4-May-10 22:38
The Man from U.N.C.L.E.4-May-10 22:38 
GeneralRe: Convert into Char Pin
Richard MacCutchan5-May-10 0:44
mveRichard MacCutchan5-May-10 0:44 
GeneralRe: Convert into Char Pin
supercat96-May-10 7:02
supercat96-May-10 7:02 
GeneralRe: Convert into Char Pin
Anubhava Dimri6-May-10 18:34
Anubhava Dimri6-May-10 18:34 
AnswerRe: Convert into Char [modified] Pin
Estys4-May-10 23:22
Estys4-May-10 23:22 
QuestionMessage Removed Pin
4-May-10 13:11
gmhanna4-May-10 13:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.