Search Tools Links Login

KB/MB/GB memory converter


Visual Basic 6, or VB Classic

Change bytes to KB/MB/GB to 2 decimal places

Original Author: Anil Upadhyay

Inputs

Input - Long value (Bytes)

Returns

Ouput - KB/MB/GB to 2 decimal places

Side Effects

None yet

Code

Public Function convertmeg(HDD As Long)
'Convert to Kb/MB/GB
Dim counter, unitcounter As Integer
Dim HDDasD As Double 'hdd as double conversion required for decimals
Dim unit As String 'bytes, kb, mb, gb
unitcounter = 0
HDDasD = HDD
'Loop
For counter = 0 To 3
  If HDDasD > 1024 Then
  HDDasD = (HDDasD / 1024)
  unitcounter = unitcounter + 1
  End If
Next
If unitcounter = 0 Then unit = "Bytes"
If unitcounter = 1 Then unit = "KB"
If unitcounter = 2 Then unit = "MB"
If unitcounter = 3 Then unit = "GB"

HDDasD = Format(HDDasD, "#0.00")  '2 decimal places
convertmeg = HDDasD
End Function

About this post

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

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.