我正在制作一个计算机科学的控制台应用程序,如果两个数字相同则显示一条消息,如果它们不同则显示不同的消息.
到目前为止,这是我的代码:
Module Module1
Sub Main()
Dim NumberOne As Integer
Dim NumberTwo As Integer
Console.WriteLine("Enter your first number and then press the enter key")
NumberOne = Console.ReadLine
Console.WriteLine("Now enter your second number and press the enter key")
NumberTwo = Console.ReadLine
If NumberOne = NumberTwo Then
Console.WriteLine("You entered the same two numbers!")
Console.ReadLine()
End If
If NumberOne <= NumberTwo Then
Console.WriteLine("You entered two different numbers")
Console.ReadLine()
End If
End Sub
End Module
Run Code Online (Sandbox Code Playgroud)
这样运行正常,但问题是如果输入两个相同的数字,它表示您输入了相同的数字,但是当您按Enter键时,它会显示另一条消息,表示您输入了两个不同的数字.
有谁知道我怎么能做到只做一个或另一个?
谢谢,
可靠的人
这个真的把我搞糊涂了。我正在尝试做一个 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 …
Run Code Online (Sandbox Code Playgroud)