VB MsgBox vbYesNo未声明

时间:2015-10-15 11:50:59

标签: vb.net

我有一个简单的程序部分,它会导致错误:VB MsgBox YesNo not declared。

如果重要,请使用Visual Studio Express 2012和Windows 7.

  

未声明VbYesNo。由于其保护级别,它可能无法访问。

非常感谢麻烦不会发生在过去。

哪个程序有问题:

userchoice = MsgBox("Did you mean to enter A?", vbYesNno, "Yes") ' if yes add, if no subtract

所有节目:

Public Class MainForm
Public stroperation, strnumber1, strnumber2, strresult As String
Public decnumber1, decnumber2, decresult As Decimal
Public operation, userchoice
Private Sub calculateButton_Click(sender As Object, e As EventArgs) Handles calculateButton.Click
    operation = operationTextBox.Text
    stroperation = CStr(operation)
    strnumber1 = number1TextBox.Text
    decnumber1 = CDec(strnumber1)
    strnumber2 = number2TextBox.Text
    decnumber2 = CDec(strnumber2)
    If stroperation = "S" Or stroperation = "s" Then
        decresult = decnumber1 - decnumber2
        strresult = CStr(decresult)
        resultLabel.Text = "Difference: " & strresult
    ElseIf stroperation = "A" Or stroperation = "a" Then
        decresult = decnumber1 + decnumber2
        strresult = CStr(decresult)
        resultLabel.Text = "Sum: " & strresult
    Else
        userchoice = MsgBox("Did you mean to enter A?", vbYesNno, "Yes") ' if yes add, if no subtract
        If userchoice = vbYes Then
            decresult = decnumber1 + decnumber2
            strresult = CStr(decresult)
            resultLabel.Text = "Sum: " & strresult
        ElseIf userchoice = vbNo Then
            decresult = decnumber1 - decnumber2
            strresult = CStr(decresult)
            resultLabel.Text = "Difference: " & strresult
        End If
    End If
End Sub

Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class

2 个答案:

答案 0 :(得分:3)

你有一个错字:

userchoice = MsgBox("Did you mean to enter A?", vbYesNno, "Yes") 

注意“Nn”。它应该是vbYesNo

答案 1 :(得分:0)

If MsgBox("Are You Sure ?", vbYesNo, "Yes") = MsgBoxResult.Yes Then            
    MsgBox("Yes")
Else
    MsgBox("No")
End If