by Adam Orenstein (6 Submissions)
Category: Data Structures
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (5 Votes)
with my code you can input a number of bytes and it will tell you how many Kilobytes Megabytes or Giga bytes it is equal to.
Assumes
it pretty self explanatory
API DeclarationsPublic Enum BYTEVALUES
KiloByte = 1024
MegaByte = 1048576
GigaByte = 107374182
End Enum
Public Function CutDecimal(Number As String, ByPlace As Byte) As String
Dim Dec As Byte
Dec = InStr(1, Number, ".", vbBinaryCompare) ' find the Decimal
If Dec = 0 Then
CutDecimal = Number 'if there is no decimal Then dont do anything
Exit Function
End If
CutDecimal = Mid(Number, 1, Dec + ByPlace) 'How many places you want after the decimal point
End Function
Function GiveByteValues(Bytes As Double) As String
If Bytes < BYTEVALUES.KiloByte Then
GiveByteValues = Bytes & " Bytes"
ElseIf Bytes >= BYTEVALUES.GigaByte Then
GiveByteValues = CutDecimal(Bytes / BYTEVALUES.GigaByte, 2) & " Gigabytes"
ElseIf Bytes >= BYTEVALUES.MegaByte Then
GiveByteValues = CutDecimal(Bytes / BYTEVALUES.MegaByte, 2) & " Megabytes"
ElseIf Bytes >= BYTEVALUES.KiloByte Then
GiveByteValues = CutDecimal(Bytes / BYTEVALUES.KiloByte, 2) & " Kilobytes"
End If
End Function