我在VB上有这段代码。我没有得到语法错误,但在运行和测试数字时,我得到“数字无效”或错误的答案。你能帮我解释一下这段代码有什么问题吗?谢谢。if,elseif,searching,comparison,greater,smaller
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox2.Text = ""
Dim Num As Integer
Dim str As String
str = TextBox1.Text
Num = Integer.Parse(str)
If Num >= 100 And Num <= 199 Then
TextBox2.Text = "Basement"
ElseIf Num >= 200 And Num <= 500 And Num >= 900 Then
TextBox2.Text = "Main Floor"
ElseIf Num <= 700 And Num >= 501 And Num >= 750 And Num <= 900 Then
TextBox2.Text = "Upper Floor"
ElseIf Num <= 750 And Num >= 700 Then
TextBox2.Text = "Archives"
Else
TextBox2.Text = "Number is not valid"
End If
End Sub
VS带有一个调试器,它非常适合解决这类问题。您也应该参加[tour] – Plutonix
不要以为您的文本框中有一个有效的号码。改为使用[Integer.TryParse](https://msdn.microsoft.com/en-us/library/f02979c7(v = vs.110).aspx)。 – LarsTech
** [橡皮鸭调试](https://en.wikipedia.org/wiki/Rubber_duck_debugging)** – Plutonix