测字符串大小函数
VB中有没有专门测字符串大小的函数?
[解决办法]
如果检测大小写:
Function IsUpperCase(a As String) As Boolean
If (a = UCase(a)) Then
IsUpperCase = True
Else
IsUpperCase = False
End If
End Function
Function IsLowerCase(a As String) As Boolean
If (a = LCase(a)) Then
IsLowerCase = True
Else
IsLowerCase = False
End If
End Function
Private Sub Form_Load()
Dim a As String
Dim b As String
a = "cb "
b = "AB "
Debug.Print IsUpperCase(a)
Debug.Print IsLowerCase(a)
Debug.Print IsUpperCase(b)
End Sub
[解决办法]
Private Declare Function lstrlen Lib "kernel32 " Alias "lstrlenA " (ByVal lpString As String) As Long
'输入字符串,返回字符串的大小,单位:(KB)
Function CalcSize(ByVal strIn As String) As Single
Dim ret As Single
If strIn <> " " Then
lstrlen (strIn)
ret = lstrlen(strIn) / 1024
End If
CalcSize = ret
End Function
Private Sub Command1_Click()
MsgBox "计算结果为: " & FormatNumber(CalcSize( "唐细刚 "), 8) & " KB "
End Sub
'如果要返回M为单位,再除以 1024 即可