怎样用vb的if语句写一个判断字母是否为大小写的程序?
答案:4 悬赏:80 手机版
解决时间 2021-11-07 05:00
- 提问者网友:棒棒糖
- 2021-11-06 23:18
怎样用vb的if语句写一个判断字母是否为大小写的程序?
最佳答案
- 五星知识达人网友:底特律间谍
- 2021-11-07 00:26
可以,示例如下:
Dim a As String
a = InputBox("输入一个字符:")
a = Trim(a)
If Len(a) < 1 Then Exit Sub
a = Left(a, 1)
If Asc(a) > 64 And Asc(a) < 91 Then
MsgBox "大写字母"
ElseIf Asc(a) > 96 And Asc(a) < 123 Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
Dim a As String
a = InputBox("输入一个字符:")
a = Trim(a)
If Len(a) < 1 Then Exit Sub
a = Left(a, 1)
If Asc(a) > 64 And Asc(a) < 91 Then
MsgBox "大写字母"
ElseIf Asc(a) > 96 And Asc(a) < 123 Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
全部回答
- 1楼网友:七十二街
- 2021-11-07 03:03
VB6:
在窗体里新建Text1 Command1
Private Sub Command1_Click()
If Asc(Text1.Text) > 90 Then MsgBox "小写 " & Text1.Text
If Asc(Text1.Text) < 91 Then MsgBox "大写 " & Text1.Text
End Sub
Private Sub Form_Load()
Text1.MaxLength = 1
End Sub
输入一个英文字母(大小写均可) 点按钮判断
在窗体里新建Text1 Command1
Private Sub Command1_Click()
If Asc(Text1.Text) > 90 Then MsgBox "小写 " & Text1.Text
If Asc(Text1.Text) < 91 Then MsgBox "大写 " & Text1.Text
End Sub
Private Sub Form_Load()
Text1.MaxLength = 1
End Sub
输入一个英文字母(大小写均可) 点按钮判断
- 2楼网友:孤独的牧羊人
- 2021-11-07 02:48
Public Enum Cased
isL = 0 '小写
isU = 1 '大写
End Enum
Public Function StrCase(ByVal Text, Optional ByVal TypeVal As Cased = 1)
Select Case TypeVal
Case 0
For i = 1 To Len(Text)
If Asc(Mid(Text, i, 1)) >= 97 And Asc(Mid(Text, i, 1)) <= 122 Then StrCase = 1: Exit For Else StrCase = 0
Next
Case 1
For i = 1 To Len(Text)
If Asc(Mid(Text, i, 1)) >= 65 And Asc(Mid(Text, i, 1)) <= 90 Then StrCase = 1: Exit For Else StrCase = 0
Next
End Select
'返回值1是存在,0是不存在
End Function
Public Function OENumber(ByVal Value)
If Value Mod 2 = 0 Then OENumber = 0 Else OENumber = 1 '0是偶数,1是奇数
End Function
isL = 0 '小写
isU = 1 '大写
End Enum
Public Function StrCase(ByVal Text, Optional ByVal TypeVal As Cased = 1)
Select Case TypeVal
Case 0
For i = 1 To Len(Text)
If Asc(Mid(Text, i, 1)) >= 97 And Asc(Mid(Text, i, 1)) <= 122 Then StrCase = 1: Exit For Else StrCase = 0
Next
Case 1
For i = 1 To Len(Text)
If Asc(Mid(Text, i, 1)) >= 65 And Asc(Mid(Text, i, 1)) <= 90 Then StrCase = 1: Exit For Else StrCase = 0
Next
End Select
'返回值1是存在,0是不存在
End Function
Public Function OENumber(ByVal Value)
If Value Mod 2 = 0 Then OENumber = 0 Else OENumber = 1 '0是偶数,1是奇数
End Function
- 3楼网友:妄饮晩冬酒
- 2021-11-07 01:55
多种方法实现:
a = "A"
If Asc(a) > 64 And Asc(a) < 91 Then
MsgBox "大写字母"
ElseIf Asc(a) > 96 And Asc(a) < 123 Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
或
If a >= "A" And a <= "Z" Then
MsgBox "大写字母"
ElseIf a >= "a" And a <= "z" Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
或
If LCase(a) <> a Then
MsgBox "大写字母"
ElseIf UCase(a) <> a Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If追问你好,请问怎样用select语句写一个判断数字的奇偶性的程序?谢谢追答a = 123
Select Case a Mod 2
Case 0
MsgBox "偶数"
Case 1
MsgBox "奇数"
End Select追问如果我的数是0-9呢?追答只要是数字就行的
a = "A"
If Asc(a) > 64 And Asc(a) < 91 Then
MsgBox "大写字母"
ElseIf Asc(a) > 96 And Asc(a) < 123 Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
或
If a >= "A" And a <= "Z" Then
MsgBox "大写字母"
ElseIf a >= "a" And a <= "z" Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If
或
If LCase(a) <> a Then
MsgBox "大写字母"
ElseIf UCase(a) <> a Then
MsgBox "小写字母"
Else
MsgBox "非字母"
End If追问你好,请问怎样用select语句写一个判断数字的奇偶性的程序?谢谢追答a = 123
Select Case a Mod 2
Case 0
MsgBox "偶数"
Case 1
MsgBox "奇数"
End Select追问如果我的数是0-9呢?追答只要是数字就行的
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯