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
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