嗨好日子家伙,我只是想问问你的帮助对我的vb.net项目我如果else语句演技太奇怪了,而不是正确地执行代码时,我在文本框中正确答案类型就会显示出correctmsg
从形式if语句正确,但是还会显示else语句中错误的消息形式。请帮助我,在此先感谢。这是我的代码:
Private Sub submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
If Label1.Text = "Who invented the airplane?" And TextBox1.Text = "third" Then
Label2.Text = (Label2.Text) + 1
correctmsg.Show()
Label1.Text = "Who invented the telephone?"
Else
wrongmsg.Show()
End If
If Label1.Text = "Who invented the telephone?" And TextBox1.Text = "Alexander Grahambell" Then
Label2.Text = Label2.Text + 1
MsgBox("Your Answer is Correct!", MsgBoxStyle.OkOnly)
Label1.Text = "Who is the first president of the United States of America?"
Else
wrongmsg.Show()
End If
If Label1.Text = "Who is the first president of the United States of America?" And TextBox1.Text = "George Washington" Then
Label2.Text = Label2.Text + 1
Else
wrongmsg.Show()
End If
End Sub
您错误地确定了哪个 Else
块正在运行:
If Label1.Text = "Who invented the airplane?" And TextBox1.Text = "third" Then
'This block is running
Label2.Text = (Label2.Text) + 1
correctmsg.Show()
Label1.Text = "Who invented the telephone?"
Else
'This block isn't running
wrongmsg.Show()
End If
If Label1.Text = "Who invented the telephone?" And TextBox1.Text = "Alexander Grahambell" Then
'This block isn't running
Label2.Text = Label2.Text + 1
MsgBox("Your Answer is Correct!", MsgBoxStyle.OkOnly)
Label1.Text = "Who is the first president of the United States of America?"
Else
'THIS Block is running
wrongmsg.Show()
End If
我会将代码移至问题的末尾,或者Return
在更改问题后有一条语句,以停止也检查相同答案的下一组块,例如:
If Label1.Text = "Who invented the airplane?" And TextBox1.Text = "third" Then
Label2.Text = (Label2.Text) + 1
correctmsg.Show()
Label1.Text = "Who invented the telephone?"
Return 'Don't do any more checks this time around
ElseIf Label1.Text = "Who invented the airplane?"
'Reason ElseIf (In case the question was 'who invented the telephone' then the first errormessage should not not be shown)
wrongmsg.Show()
Return
End If
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句