VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



bytes to KB, MB or GB

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 Declarations
Public Enum BYTEVALUES
KiloByte = 1024
MegaByte = 1048576
GigaByte = 107374182
End Enum

Rate bytes to KB, MB or GB

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

Download this snippet    Add to My Saved Code

bytes to KB, MB or GB Comments

No comments have been posted about bytes to KB, MB or GB. Why not be the first to post a comment about bytes to KB, MB or GB.

Post your comment

Subject:
Message:
0/1000 characters