Dim i As Integer
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then MsgBox "非法字符!", vbInformation, "提示" '0-9的ASCII值为48-57
If (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii >= 65 And KeyAscii <= 90) Then 'a-z的ASCII值为97-122;A-Z的ASCII值为65-90
i = i + 1
Picture1.Cls
Picture1.Print Text1.Text + Chr(KeyAscii) + "字母的个数是" + Str(i) 'Chr()将ASCII转换为字符串;;Str()为将数值转换为字符串
End If
End Sub
Dim a(122)
Private Sub Form_Load()
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Picture1.Cls
If KeyAscii >= 48 And KeyAscii <= 57 Then MsgBox "非法字符!", vbInformation, "提示" '0-9的ASCII值为48-57
If (KeyAscii >= 97 And KeyAscii <= 122) Or (KeyAscii >= 65 And KeyAscii <= 90) Then
a(KeyAscii) = a(KeyAscii) + 1
End If
For i = 97 To 122
If a(i) <> 0 Then Picture1.Print Chr(i); "字母的个数是"; a(i)
Next
For i = 65 To 90
If a(i) <> 0 Then Picture1.Print Chr(i); "字母的个数是"; a(i)
Next
End Sub
Dim K(65 To 90) As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
KeyAscii = 0
MsgBox "非法字符!", vbExclamation, "提示"
Exit Sub
End If
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim X As Integer
For I = 1 To Len(Text1.Text)
X = Asc(Mid(Text1.Text, I, 1))
If X >= 65 And X <= 90 Then
K(X) = K(X) + 1
End If
If X >= 97 And X <= 122 Then
K(X - 32) = K(X - 32) + 1
End If
Next I
Picture1.Cls
For J = 65 To 90
Picture1.Print Chr(J) & "字母的个数是" & K(J) & "个!"
K(J) = 0
Next J
End Sub
PS:请问label是干嘛用的?
ascii 表 用ASC函数返回字符代码 如果在字符代码范围添加