Click here to Skip to main content
16,005,281 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
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 
I knew it would error for extremely large sizes and failed on negatives so here's a fix. (Not sure the negatives a right.)
Public Function FormattedFileSize(ByVal sizeInBytes As Long) As String
   Dim suffix() As String = New String() {"Oops", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "XX"}
   Dim units As Double = Math.Abs(sizeInBytes) 'Fudge to deal with negatives. Should it error with neg file size?
   Dim index As Integer = 0

   Do
      units = units / 1024.0
      index += 1
   Loop While units >= 1024.0

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

I've not done homework for years. Smile | :)
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
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 
AnswerRe: SQL Update "Update requires a valid update command" Pin
Johan Hakkesteegt4-May-10 23:43
Johan Hakkesteegt4-May-10 23:43 
QuestionLooping through a repeater Pin
Dayekh4-May-10 6:18
Dayekh4-May-10 6:18 

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.