Jak*_*rew 2 vb.net console-application
这个真的把我搞糊涂了。我正在尝试做一个 Visual Basic 控制台应用程序,如果用户输入“A”或“a”,那么程序应该执行“x”,但这不起作用。我得到的错误是:
从字符串“a”到类型“Boolean”的转换无效。
这是我的代码:
模块模块1
Sub Main()
Dim Selection As String
Console.WriteLine("Please select your function:")
Console.WriteLine("* To convert binary to decimal, press A,")
Console.WriteLine("* Or to convert decimal to binary, press B")
Selection = Console.ReadLine
If Selection = "A" Or "a" Then
Console.WriteLine("This will be A")
ElseIf Selection = "B" Or "b" Then
Console.WriteLine("This will be B")
ElseIf Selection = Not "A" Or "a" Or "B" Or "b" Then
Console.WriteLine("Please try again")
Do Until Selection = "A" Or "a" Or "B" Or "b"
Loop
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
这段代码中 Or 的正确用法应该是什么才能使其正常运行?
谢谢,
杰克
你的If
条款应该是这样的:
If Selection = "A" Or Selection = "a" Then
Run Code Online (Sandbox Code Playgroud)
之间的条款Or
应每个是布尔表达式,并且"a"
仅仅是一个字符,而不是一个布尔表达式。
归档时间: |
|
查看次数: |
15498 次 |
最近记录: |