VB.Net上的其他行为很奇怪

新手

嗨好日子家伙,我只是想问问你的帮助对我的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
Damien_The_Unbeliever

您错误地确定了哪个 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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在点击事件(VB.net)上从其他页面传递变量值

来自分类Dev

自动在vb.net中单击其他形式的按钮

来自分类Dev

VB.NET - 导航而不加载其他表单

来自分类Dev

VB.net 从其他线程更新标签

来自分类Dev

在vb.net中随机表演奇怪

来自分类Dev

VB.Net中的接口行为不同

来自分类Dev

VB.Net DatagridviewComboBoxColumn CellClick行为

来自分类Dev

VB.NET和VB之间的区别

来自分类Dev

在ASP.NET(VB)中串联两个字符串时出现奇怪的行为

来自分类Dev

VB NET,累积损坏

来自分类Dev

VB Net IsDBNull问题

来自分类Dev

Vb.net-FolderBrowserDialog

来自分类Dev

VB.NET FolderBrowserDialog

来自分类Dev

Vb.Net-UpdateDriverForPlugAndPlayDevices

来自分类Dev

Vb.net-FolderBrowserDialog

来自分类Dev

VB.NET VbNewLine

来自分类Dev

VB.NET与多态

来自分类Dev

VB.NET将控件分配给其他控件

来自分类Dev

如何在VB.NET中将表单保持在其他表单之上?

来自分类Dev

VB.NET:在其他子程序的循环期间如何维护主窗体控制?

来自分类Dev

在VB.net中,如何从嵌套类中的其他函数访问类中的函数?

来自分类Dev

VB NET。当其他事件被触发时,如何触发一个事件?

来自分类Dev

如何在VB.NET中将表单保留在其他表单之上?

来自分类Dev

无法引用VB.net程序其他模块中的子例程

来自分类Dev

尝试引用VB.net程序其他模块中的子例程时出错

来自分类Dev

如何在vb.net中显示其他表格中的特定选项卡

来自分类Dev

在VB.NET REST上捕获JSON

来自分类Dev

Resharper在VB.NET缩进上发疯

来自分类Dev

vb.net listview 上的分页项