2014-01-31 95 views
0

第一个IF语句确实运行良好,其他IF语句不起作用。当我点击按钮什么都没有发生。第一个IF语句运行良好,而下一个IF语句不再有效

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    If TextBox1.Text.Trim = "What is your name?" Then 
     Label1.Text = "Hi there kid! I will tell you later!" 
     Return 
     If TextBox1.Text.Trim = "What is your age?" Then 
      Label1.Text = "I was made in January 31,2014 well that is my birth date!" 
      Return 



      If TextBox1.Text = "Hi" Then 
       Label1.Text = "Hi there also!" 

      Else 
       Label1.Text = "Do you have anything you want to say other than that?" 
      End If 
     End If 
    End If 
End Sub 
+0

使用“返回”退出了事件处理程序 – Jesse

+0

@Jesse当我删除返回它仍然行为相同..:*( – TheNewbie

+1

你IFS也嵌套,它TextBox1.Text是不可能的.Trim等于“你的年龄?”,如果它已经等于“你的名字是什么?” – Jesse

回答

2

我想你可以删除的回报,并使用否则,如果为其他如果。它应该是罚款

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    If TextBox1.Text.Trim = "What is your name?" Then 
     Label1.Text = "Hi there kid! I will tell you later!" 

    else if TextBox1.Text.Trim = "What is your age?" Then 
     Label1.Text = "I was made in January 31,2014 well that is my birth date!" 

    else if TextBox1.Text = "Hi" Then 
     Label1.Text = "Hi there also!" 

    Else 
     Label1.Text = "Do you have anything you want to say other than that?" 

    End If 

End Sub 
+0

非常感谢你给这个代码工作像一个魅力但是我删除了2结束ifs因为它不是必要的:) – TheNewbie

0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    If TextBox1.Text.Trim = "What is your name?" Then 
     Label1.Text = "Hi there kid! I will tell you later!" 
    End If 
    If TextBox1.Text.Trim = "What is your age?" Then 
     Label1.Text = "I was made in January 31,2014 well that is my birth date!" 
    End If 
    If TextBox1.Text = "Hi" Then 
     Label1.Text = "Hi there also!" 
    Else 
     Label1.Text = "Do you have anything you want to say other than that?" 
    End If 
End Sub 

试一下

+0

而是它显示了else语句而不是if语句。 – TheNewbie