SmileConvert Byte to Mb

Posts 1–6 of 6 · Page 1 of 1
Convert Byte to Mb
How do i convert Byte to Mb!

And if i use label1.text = myfilehere / 1024

I get like 105,8408448

So is it possible to round up or convert it to like 2.0?

//H
how about, on topic...


@ Convert Bytes to MB

Code:
Public Function BytesToMegabytes(Bytes As Double) As Double
   
  Dim mathbtmb As Double
  math = (Bytes / 1024) / 1024
  BytesToMegabytes = Format(mathbtmb, "###,###,##0.00") ' 0 for more decimal     places.
  
End Function
or you can use if statements and return value

Code:
Function Numeric2Bytes(ByVal b As Double) As String
    Dim byteSize(8) As String
    Dim i As Integer

    byteSize(0) = "Bytes"
    byteSize(1) = "KB" 
    byteSize(2) = "MB" 
    
    b = CDbl(b) 
    For i = UBound(bytesize) To 0 Step -1
        If b >= (1024 ^ i) Then
            Numeric2Bytes = ThreeNonZeroDigits(byte / (1024 ^ _
                i)) & " " & byteSize(i)
            Exit For
        End If
    Next
End Function

Private Function ThreeNonZeroDigits(ByVal value As Double) _
    As String
    If value >= 100 Then
        Return Format$(CInt(value))
    ElseIf value >= 10 Then
              Return Format$(value, "0.0")
    Else
            Return Format$(value, "0.00")
    End If
End Function
Or

Play around the hard way, if your converting only bytes to mb, use the formula in code box one, and create if statments ,

example :

Code:
If mathbytes >= 1.890 then 
label1.text = 2 'or whatever 
end if ' or else
end if
Hope this helps
Quote Originally Posted by NextGen1 View Post
how about, on topic...


@ Convert Bytes to MB

Code:
Public Function BytesToMegabytes(Bytes As Double) As Double
   
  Dim mathbtmb As Double
  math = (Bytes / 1024) / 1024
  BytesToMegabytes = Format(mathbtmb, "###,###,##0.00") ' 0 for more decimal     places.
  
End Function
or you can use if statements and return value

Code:
Function Numeric2Bytes(ByVal b As Double) As String
    Dim byteSize(8) As String
    Dim i As Integer

    byteSize(0) = "Bytes"
    byteSize(1) = "KB" 
    byteSize(2) = "MB" 
    
    b = CDbl(b) 
    For i = UBound(bytesize) To 0 Step -1
        If b >= (1024 ^ i) Then
            Numeric2Bytes = ThreeNonZeroDigits(byte / (1024 ^ _
                i)) & " " & byteSize(i)
            Exit For
        End If
    Next
End Function

Private Function ThreeNonZeroDigits(ByVal value As Double) _
    As String
    If value >= 100 Then
        Return Format$(CInt(value))
    ElseIf value >= 10 Then
              Return Format$(value, "0.0")
    Else
            Return Format$(value, "0.00")
    End If
End Function
Or

Play around the hard way, if your converting only bytes to mb, use the formula in code box one, and create if statments ,

example :

Code:
If mathbytes >= 1.890 then 
label1.text = 2 'or whatever 
end if ' or else
end if
Hope this helps
Awesome, thanks!
No problem, hope it works out for you
been wondering how to do this myself. thx
Problem solved. Request close.

Edit: removed the !
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us