VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



KB/MB/GB memory converter

by Anil Upadhyay (2 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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

Inputs
Input - Long value (Bytes)
Code Returns
Ouput - KB/MB/GB to 2 decimal places
Side Effects
None yet

Rate KB/MB/GB memory converter

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

Download this snippet    Add to My Saved Code

KB/MB/GB memory converter Comments

No comments have been posted about KB/MB/GB memory converter. Why not be the first to post a comment about KB/MB/GB memory converter.

Post your comment

Subject:
Message:
0/1000 characters