第一个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 :(得分:2)
我认为你可以删除return并使用else,如果是另一个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!"
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
答案 1 :(得分: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
试试