Thursday, June 28, 2007

Bytes Converter Function

A simple function that converts Bytes to GB, MB or KB.

Code Snippet:

  1. Function SetBytes(Bytes,fKB)
  2. if fKB=True then Bytes = Bytes * 1024
  3. If Bytes >= 1073741824 Then
  4. SetBytes = FormatNumber((Bytes / 1024 / 1024 / 1024),2,,-1,-1) & " GB"
  5. ElseIf Bytes >= 1048576 Then
  6. SetBytes = FormatNumber((Bytes / 1024 / 1024),2,,-1,-1) & " MB"
  7. ElseIf Bytes >= 1024 Then
  8. SetBytes = FormatNumber((Bytes / 1024),2,,-1,-1) & " KB"
  9. ElseIf Bytes < 1024 Then
  10. SetBytes = Bytes & " Bytes"
  11. End If
  12. End Function

Usage: SetBytes(Size,true\false)

If at first you fail, call it version 1.0

No comments: