输入字符串,统计大写、小写、英文、数字 VB

2024-12-12 11:07:24
推荐回答(1个)
回答1:

VB本身没有这个功能,可以通过以下方法实现:
在窗体放一个Command和Text控件,点击Command1将出结果。
代码:
Private Sub Command1_Click()
Dim A As String, S As String, I As Integer, W As Integer, X As Integer, Y As Integer, Z As Integer
If Text1.Text = "" Then Text1.Text = "0123456789abcdefABCDEFGHIJKLMN大家好!"
A = Text1.Text’需要计算的字符串
For I = 1 To Len(A)
S = Right(Left(A, I), 1)
If Asc(S) > 64 And Asc(S) < 91 Then W = W + 1 '大写
If Asc(S) > 96 And Asc(S) < 123 Then X = X + 1 '小写
If Asc(S) > 64 And Asc(S) < 91 Or Asc(S) > 96 And Asc(S) < 123 Then Y = Y + 1 '英文
If Asc(S) > 47 And Asc(S) < 58 Then Z = Z + 1 '数字
DoEvents '如字符很长,会感觉象死机,所以转让控制权,以便让操作系统处理其它的事件
Next
MsgBox "总长:" & Len(A) & vbCrLf & "大写:" & W & vbCrLf & "小写:" & X & vbCrLf & "英文:" & Y & vbCrLf & "数字:" & Z & vbCrLf & "其它:" & Len(A) - Y - Z
End Sub