我通过程序已经获得了文件大小
set FileObj = Filesys.GetFile("文件名")
kk = FileObj.size
问题:
如何使用select Case 编写
kk/1024/1024>0 --- dubug.print cstr(rount(kk)) & "MB" 
kk/1024>0 --- dubug.print cstr(rount(kk)) & "KB" 
kk>0 --- dubug.print cstr(rount(kk)) & "B" 
我用的方法是
select case kk
  case kk/1024/1024>0
    dubug.print cstr(rount(kk)) & "MB" 
  case kk/1024>0
    dubug.print cstr(rount(kk)) & "kB" 
  case kk>0
    dubug.print cstr(rount(kk)) & "B" 
end select 
运行不通过
请教各位大侠,如何解决,谢谢.

解决方案 »

  1.   

    '字节转换(第一个参数为字节数,第二个为保留小数位数,第三个为是否显示单位)
    Public Function ConvertBytes(Bytes As Double, Optional DecimalPlaces As Byte = 2, Optional ShowSuffix As Boolean = True) As String
        Select Case Bytes
            Case 0 To 1023 'Bytes
                ConvertBytes = FormatNumber(Bytes, 0)
                If ShowSuffix Then ConvertBytes = ConvertBytes & " bytes"
            Case 1024 To 1048575 'KB
                ConvertBytes = FormatNumber(Bytes / 1024, DecimalPlaces)
                If ShowSuffix Then ConvertBytes = ConvertBytes & " KB"
            Case 1048576 To 1073741823 'MB
                ConvertBytes = FormatNumber(Bytes / 1048576, DecimalPlaces)
                If ShowSuffix Then ConvertBytes = ConvertBytes & " MB"
            Case Else 'GB
                ConvertBytes = FormatNumber(Bytes / 1073741824, DecimalPlaces)
                If ShowSuffix Then ConvertBytes = ConvertBytes & " GB"
        End Select
    End FunctionPrivate Sub Command11_Click() '字节值转换为单位
        sByte = ConvertBytes(nByte, 2, True) '保留2位小数,显示单位
    End Sub