当你键入(A,I,O,U,E)计数字符时我需要一个代码..我写了这个但它不起作用..请帮帮我..抱歉我的英语不好
n = Val(InputBox("enter a number"))
For i = 1 To Len(n)
k = Mid(n, i, 1)
k = LCase k
Select Case k
Case "a""i""o""u""e": t = t + 1
End Select
Next
Print t
答案 0 :(得分:5)
val()
会将输入值转换为数字,因此永远不会有任何元音..删除它并更正案例条件中缺少的逗号:
Dim n As String, t As Long
n = InputBox("enter a number")
For i = 1 To Len(n)
Select Case LCase$(Mid$(n, i, 1))
Case "a", "i", "o", "u", "e": t = t + 1
End Select
Next
Print t
答案 1 :(得分:3)
您正在检查文字字符串a"i"o"u"e
,这显然不是您的意图。
您可能打算:
n = Val(InputBox("enter a number"))
For i = 1 To Len(n)
k = Mid(n, i, 1)
k = LCase k
Select Case k
Case "a", "i", "o", "u", "e": t = t + 1
End Select
Next
Print t
您可read here了解Case
语句的工作原理。