Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting bytes into KB,MB,GB,TB,PB
#1
I needed a little function for convert bytes into KB,MB,GB,TB,PB.
Here she is..

Code: (Select All)
'Convert Bytes in KB,MB,GB,TB,TB
'put also spaces in long numbers

A$ = "123122555552344566": Print " "; CHIFFRESPACE$(A$)
A$ = "234855666": Print " "; CHIFFRESPACE$(A$)
A$ = "6000234855666": Print " "; CHIFFRESPACE$(A$)
A$ = "512445666": Print " "; CHIFFRESPACE$(A$)
A$ = "512": Print " "; CHIFFRESPACE$(A$)
A$ = "14265444444": Print " "; CHIFFRESPACE$(A$)
A$ = "1355": Print " "; CHIFFRESPACE$(A$)

Sleep
End




Function CHIFFRESPACE$ (D$)
    DD$ = D$: OCTEX$ = D$: DD1$ = "": sauto = 0
    For yu = Len(DD$) To 1 Step -1
        DD1$ = Mid$(DD$, yu, 1) + DD1$: sauto = sauto + 1: If sauto = 3 Then DD1$ = " " + DD1$: sauto = 0
    Next yu
    XCHIF$ = OCTEX$: YCHIF# = Val(XCHIF$)
    NBC = Int((Log(Val(XCHIF$)) / 2.303) + 1.01) 'number of digits... in OCTEX$
    If NBC < 4 Then FF$ = XCHIF$: UND$ = "bytes": GoTo aa
    If NBC < 7 Then ZCHIF# = Int(YCHIF# / 1024 * 10000) / 10000: FF$ = Str$(ZCHIF#): UND$ = "KB": GoTo aa
    If NBC < 10 Then ZCHIF# = Int(YCHIF# / 1024 / 1024 * 10000) / 10000: FF$ = Str$(ZCHIF#): UND$ = "MB": GoTo aa
    If NBC < 13 Then ZCHIF# = Int(YCHIF# / 1024 / 1024 / 1024 * 10000) / 10000: FF$ = Str$(ZCHIF#): UND$ = "GB": GoTo aa
    If NBC < 16 Then ZCHIF# = Int(YCHIF# / 1024 / 1024 / 1024 / 1024 * 10000) / 10000: FF$ = Str$(ZCHIF#): UND$ = "TB": GoTo aa
    ZCHIF# = Int(YCHIF# / 1024 / 1024 / 1024 / 1024 / 1024 * 10000) / 10000: FF$ = Str$(ZCHIF#): UND$ = "PB"
    aa: FF$ = _Trim$(FF$): If Left$(FF$, 1) = "." Then FF$ = "0" + FF$
    If InStr(FF$, ".") = 0 Then FF$ = FF$ + ".0000"
    JFF = InStr(FF$, "."): FF$ = Left$(FF$ + "0000000000000000", JFF + 4)
    JFF = InStr(FF$, "."): Mid$(FF$, JFF, 1) = ","
    Octey$ = "         (" + FF$ + " " + UND$ + ")"
    DD1$ = Left$(_Trim$(DD1$) + " bytes" + String$(60, 32), 55): W = Len(Octey$): Mid$(DD1$, Len(DD1$) - W, Len(Octey$)) = Octey$
    CHIFFRESPACE$ = DD1$

End Function
Why not yes ?
Reply


Messages In This Thread
Converting bytes into KB,MB,GB,TB,PB - by euklides - 05-30-2025, 02:47 PM



Users browsing this thread: 1 Guest(s)