VB编程 已知字符型变量ch中存放一个字符,判断该字符是字母、数字还是其它字符,并给出相应的显示。

期末考试的题啊成功了再加30分~
2024-12-04 04:34:19
推荐回答(2个)
回答(1):

Private Sub Command1_Click()
Dim ch As String
ch = Chr(Int(Rnd * 200) + 1)
Print ch;
If Asc(ch) >= Asc("A") And Asc(ch) <= Asc("Z") Then
MsgBox "这是一个大写字母", , "提示"
ElseIf Asc(ch) >= Asc("a") And Asc(ch) <= Asc("z") Then
MsgBox "这是一个小写字母", , "提示"
ElseIf Asc(ch) >= Asc("0") And Asc(ch) <= Asc("9") Then
MsgBox "这是一个数字", , "提示"
Else
MsgBox "非字母或数字", , "提示"
End If
End Sub

回答(2):

用ascii,码判断很简单嘛

Private Sub Form_Load()
Dim ch As String * 1
ch = "a"
If ((Asc(ch) >= 65 And Asc(ch) <= 90) Or (Asc(ch) >= 97 And Asc(ch) <= 122)) Then
MsgBox "字母"
ElseIf Asc(ch) >= 48 And Asc(ch) <= 57 Then
MsgBox "数字"
Else
MsgBox "其它字符"
End If
End Sub