منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : تحويل التنسيق بايت الي Kb- Mb- Gb بالكود
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
كاتب الموضوع : AhmedEssawy

مثال
  • SetBytes(74) 'returns "74 Bytes"
  • SetBytes(5037) 'returns "4.92 KB"
  • SetBytes(6383838) 'returns "6.09 MB"
  • SetBytes(3368383278) 'returns "3.14 GB"



كود :
Function SetBytes(Bytes) As String

On Error GoTo hell

If Bytes >= 1073741824 Then
SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") _
& " GB"
ElseIf Bytes >= 1048576 Then
SetBytes = Format(Bytes / 1024 / 1024, "#0.00") & " MB"
ElseIf Bytes >= 1024 Then
SetBytes = Format(Bytes / 1024, "#0.00") & " KB"
ElseIf Bytes < 1024 Then
SetBytes = Fix(Bytes) & " Bytes"
End If

Exit Function
hell:
SetBytes = "0 Bytes"
End Function