|
vrodrigues -> RE: Script for collecting logical disk info (10/8/2008 12:09:01 PM)
|
Here's a function I created that will convert Byte size to kB, MB, GB, TB, etc... This will help make the bytes all little more readable. Function ConvertByteSize(Size) Dim CommaLocate Dim suffix Const NumDecimalPlaces = 2 Do While InStr(Size,",") 'Remove commas from size CommaLocate = InStr(Size,",") Size = Mid(Size,1,CommaLocate - 1) & _ Mid(Size,CommaLocate + 1,Len(Size) - CommaLocate) Loop Suffix = " Bytes" If Size >= 1024 Then suffix = " kiloBytes (kB)" ' binary multipliers are 2 to the 10th power or 1024 to the 1st power If Size >= 1048576 Then suffix = " MegaBytes (MB)" ' binary multipliers are 2 to the 20th power or 1024 to the 2nd power If Size >= 1073741824 Then suffix = " GigaBytes (GB)" ' binary multipliers are 2 to the 30th power or 1024 to the 3rd power If Size >= 1099511627776 Then suffix = " TeraBytes (TB)" ' binary multipliers are 2 to the 40th power or 1024 to the 4th power If Size >= 1125899906842624 Then suffix = " PetaBytes (PB)" ' binary multipliers are 2 to the 50th power or 1024 to the 5th power If Size >= 1152921504606846976 Then suffix = " ExaBytes (EB)" ' binary multipliers are 2 to the 60th power or 1024 to the 6th power If Size >= 1180591620717411303424 Then suffix = " ZettaBytes (ZB)" ' binary multipliers are 2 to the 70th power or 1024 to the 7th power If Size >= 1208925819614629174706176 Then suffix = " YottaBytes (YB)" ' binary multipliers are 2 to the 80th power or 1024 to the 8th power Select Case Suffix Case " kiloBytes (kB)" Size = Round(Size / 1024, NumDecimalPlaces) Case " MegaBytes (MB)" Size = Round(Size / 1048576, NumDecimalPlaces) Case " GigaBytes (GB)" Size = Round(Size / 1073741824, NumDecimalPlaces) Case " TeraBytes (TB)" Size = Round(Size / 1099511627776, NumDecimalPlaces) Case " PetaBytes (PB)" Size = Round (Size / 1125899906842624, NumDecimalPlaces) Case " ExaBytes (EB)" Size = Round(Size / 1152921504606846976, NumDecimalPlaces) Case " ZettaBytes (ZB)" Size = Round(Size / 1180591620717411303424, NumDecimalPlaces) Case " YottaBytes (YB)" Size = Round(Size / 1208925819614629174706176, NumDecimalPlaces) End Select ConvertByteSize = Size & Suffix End Function
|
|
|
|