Search Tools Links Login

bytes to KB, MB or GB

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.

Original Author: Adam Orenstein


it pretty self explanatory

API Declarations

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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 105 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.