Vb.net 出现对话框后,如何停止程序的执行

Vb.net 出现对话框后,如何停止程序的执行,vb.net,Vb.net,我有一个问题,我的代码,一个简单的订单需要某些信息。当用户未输入一条信息时,程序会显示一个对话框,然后在用户点击OK后,程序仍会计算该信息。我是VB新手,下面是代码片段: If (CheckBox3.Checked = False And blueBlackQuantityTextBox.Text <> "" And blueBlackQuantityTextBox.Text > 0) Then MessageBox.Show("Please check it

我有一个问题,我的代码,一个简单的订单需要某些信息。当用户未输入一条信息时,程序会显示一个对话框,然后在用户点击OK后,程序仍会计算该信息。我是VB新手,下面是代码片段:

 If (CheckBox3.Checked = False And blueBlackQuantityTextBox.Text <> "" And blueBlackQuantityTextBox.Text > 0) Then
        MessageBox.Show("Please check item you wish to purchase", "No Item Selected",
      MessageBoxButtons.OK, MessageBoxIcon.Error)
        Stop
    End If

    Const whiteBlackDicePrice = 6.25
    Const redBlackDicePrice = 5.0
    Const blueBlackDicePrice = 7.5
    Const tax = 0.05

    Dim whiteBlackSubTotal As Double = whiteBlackQuantityTextBox.Text *      whiteBlackDicePrice
    Dim redBlackSubTotal As Double = redBlackQuantityTextBox.Text * redBlackDicePrice
    Dim blueBlackSubtotal As Double = blueBlackQuantityTextBox.Text * blueBlackDicePrice
    'newBalanceResultLabel.Text = String.Format("{0:C2}", newBalance)

    Dim subtotal As Double = whiteBlackSubTotal + redBlackSubTotal + blueBlackSubtotal

    whiteBlackTotalsLabel.Text = String.Format("{0:C2}", whiteBlackSubTotal)
    redBlackTotalsLabel.Text = String.Format("{0:C2}", redBlackSubTotal)
    blueBlackTotalsLabel.Text = String.Format("{0:C2}", blueBlackSubtotal)

    subtotalResultLabel.Text = String.Format("{0:C2}", subtotal)
如果(CheckBox3.Checked=False和blueBlackQuantityTextBox.Text“”和blueBlackQuantityTextBox.Text>0),则
MessageBox.Show(“请勾选您想要购买的物品”,“未选择任何物品”,
MessageBoxButtons.OK,MessageBoxIcon.Error)
停止
如果结束
常数whiteBlackDicePrice=6.25
常数redblackdice=5.0
常数blueBlackDicePrice=7.5
常量税=0.05
Dim WhiteBlack小计为Double=whiteBlackQuantityTextBox.Text*whiteBlackDicePrice
Dim RedBlack小计为Double=redBlackQuantityTextBox.Text*redBlackDicePrice
Dim blueBlackSubtotal As Double=blueBlackQuantityTextBox.Text*blueBlackDicePrice
'newBalanceResultLabel.Text=String.Format(“{0:C2}”,newBalance)
双精度小计=白色黑色小计+红色黑色小计+蓝色lackSubtotal
whiteBlackTotalsLabel.Text=String.Format(“{0:C2}”,whiteBlackSubTotal)
redBlackTotalsLabel.Text=String.Format(“{0:C2}”,redBlackSubTotal)
blueBlackTotalsLabel.Text=String.Format(“{0:C2}”,blueBlackSubtotal)
subtotalResultLabel.Text=String.Format(“{0:C2}”,小计)
在每个IF语句后加一个STOP,会导致程序崩溃,我只能让对话框说:好的

请帮忙

If(CheckBox3.Checked=False和blueBlackQuantityTextBox.Text“”
 If (CheckBox3.Checked = False And blueBlackQuantityTextBox.Text <> "" 
       And blueBlackQuantityTextBox.Text > 0) Then

    If MessageBox.Show("Please check item you wish to purchase", 
           "No Item Selected",
           MessageBoxButtons.OK, MessageBoxIcon.Error) = DialogResult.OK Then
          Stop
    End If
 End if
和blueBlackQuantityTextBox.Text>0)然后 如果MessageBox.Show(“请勾选您想要购买的物品”, “未选择任何项目”, MessageBoxButtons.OK,MessageBoxIcon.Error)=DialogResult.OK然后 停止 如果结束 如果结束
msgbox消息和操作似乎不匹配。不清楚“No item”是否会结束程序(或中断以在设计器中调试)。也许你的意思是退出子系统?此外,因为他们有一个选择,好的,它将永远结束程序

无论如何,
MessageBox
是一个返回您可以计算的
对话框结果的函数。如果(CheckBox3.Checked=False和blueBlackQuantityTextBox.Text“”,则没有这样配置
和blueBlackQuantityTextBox.Text>0)然后
如果MessageBox.Show(“请勾选您想要购买的物品”,
“未选择任何项目”,
MessageBoxButtons.OK,MessageBoxIcon.Error)=DialogResult.OK然后
停止
如果结束
如果结束
msgbox消息和操作似乎不匹配。不清楚“No item”是否会结束程序(或中断以在设计器中调试)。也许你的意思是退出子系统?此外,因为他们有一个选择,好的,它将永远结束程序

无论如何,
MessageBox
是一个返回您可以计算的
对话框结果的函数。如果(CheckBox3.Checked=False和blueBlackQuantityTextBox.Text“”,则没有这样配置
和blueBlackQuantityTextBox.Text>0)然后
如果MessageBox.Show(“请勾选您想要购买的物品”,
“未选择任何项目”,
MessageBoxButtons.OK,MessageBoxIcon.Error)=DialogResult.OK然后
停止
如果结束
如果结束
msgbox消息和操作似乎不匹配。不清楚“No item”是否会结束程序(或中断以在设计器中调试)。也许你的意思是退出子系统?此外,因为他们有一个选择,好的,它将永远结束程序

无论如何,
MessageBox
是一个返回您可以计算的
对话框结果的函数。如果(CheckBox3.Checked=False和blueBlackQuantityTextBox.Text“”,则没有这样配置
和blueBlackQuantityTextBox.Text>0)然后
如果MessageBox.Show(“请勾选您想要购买的物品”,
“未选择任何项目”,
MessageBoxButtons.OK,MessageBoxIcon.Error)=DialogResult.OK然后
停止
如果结束
如果结束
msgbox消息和操作似乎不匹配。不清楚“No item”是否会结束程序(或中断以在设计器中调试)。也许你的意思是退出子系统?此外,因为他们有一个选择,好的,它将永远结束程序


无论如何,
MessageBox
是一个返回您可以计算的
对话框结果的函数。您没有这样配置您的程序

在这里您应该如何编写程序

Private sub MySub()

    If not ConditionsValidated() Then

        MessageBox.Show("Please check item you wish to purchase") ' MsgBox with a single button always returns Ok. Here you don't even need to tell to show Ok - this is default.
        Return
    End If

    ' your code is running here

end sub

private function ConditionsValidated() as Boolean

    ' Validate your controls here

end sub

如果有人没有选择某个内容,我也不会显示“错误”消息框。错误意味着您的应用程序遇到严重错误。这就是为什么有验证器可以在无效控件旁边显示一个小的红点,或者使控件的颜色变为红色,等等

Private sub MySub()

    If not ConditionsValidated() Then

        MessageBox.Show("Please check item you wish to purchase") ' MsgBox with a single button always returns Ok. Here you don't even need to tell to show Ok - this is default.
        Return
    End If

    ' your code is running here

end sub

private function ConditionsValidated() as Boolean

    ' Validate your controls here

end sub

如果有人没有选择某个内容,我也不会显示“错误”消息框。错误意味着您的应用程序遇到严重错误。这就是为什么有验证器可以在无效控件旁边显示一个小的红点,或者使控件的颜色变为红色,等等

Private sub MySub()

    If not ConditionsValidated() Then

        MessageBox.Show("Please check item you wish to purchase") ' MsgBox with a single button always returns Ok. Here you don't even need to tell to show Ok - this is default.
        Return
    End If

    ' your code is running here

end sub

private function ConditionsValidated() as Boolean

    ' Validate your controls here

end sub

如果有人没有选择某个内容,我也不会显示“错误”消息框。错误意味着您的应用程序遇到严重错误。这就是为什么有验证器可以在无效控件旁边显示一个小的红点,或者使控件的颜色变为红色,等等

Private sub MySub()

    If not ConditionsValidated() Then

        MessageBox.Show("Please check item you wish to purchase") ' MsgBox with a single button always returns Ok. Here you don't even need to tell to show Ok - this is default.
        Return
    End If

    ' your code is running here

end sub

private function ConditionsValidated() as Boolean

    ' Validate your controls here

end sub

如果有人没有选择某个内容,我也不会显示“错误”消息框。错误意味着您的应用程序遇到严重错误。这就是为什么有验证器可以在无效控件旁边显示一个小红点,或者使控件的颜色变为红色,等等,这是一个简单的解决方案。在任何需要的地方使用下面的代码