Question MessageBoxButtons.YesNoCancel ?

william7

Member
Joined
Mar 2, 2013
Messages
10
Programming Experience
Beginner
Can anybody tell me why the code below doesn't work? I used this same method previously with success so I can't understand what possibly I'm doing wrong.

VB.NET:
 Private Sub btnTodaysTotals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTodaysTotals.Click

       
        Dim Caption As String = "Reset form"
        Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNoCancel
        Dim Result As DialogResult
        Dim Message As String = "Sold " & QuantityOfTheDay.ToString & " Pizza(s) for " & FinalTotalOfTheDay.ToString("C") & vbNewLine & _
         "Do you wish to close "

        If Result = System.Windows.Forms.DialogResult.No Then

            Exit Sub

        End If

        'Gets the result of the MessageBox display. 
        If Result = System.Windows.Forms.DialogResult.Yes Then

        End If

        'MessageBox.Show("Sold " & QuantityOfTheDay.ToString & " Pizza(s) for " & FinalTotalOfTheDay.ToString("C") & vbNewLine & _
        ' "Do you wish to close ")
    End Sub
 
This comment is from your own code:
Gets the result of the MessageBox display.
What MessageBox? The only place you call MessageBox.Show is right at the end and that's commented out. If you want to test the value of Result then wouldn't it make sense to assign a value to Result in the first place?
 
VB.NET:
()
            Dim Caption As String = "Reset form"
            Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNoCancel
            Dim Result As DialogResult
            Dim Message As String = "Sold " & QuantityOfTheDay.ToString & " Pizza(s) for " & FinalTotalOfTheDay.ToString("C") & vbNewLine & _
             "Do you wish to close "

            Result = MessageBox.Show(Message, Caption, Buttons)

            If Result = DialogResult.No Then

                Exit Property

            ElseIf Result = System.Windows.Forms.DialogResult.Yes Then

            End If

That Code should work, although someone may give a better answer i am still very new myself.

your mistake was you where trying to check an empty result.

You wanted the result to come from what the user clicked on the message box
'Result = MessageBox.Show(Message, Caption, Buttons)'

Then you execute your code depending on the result from the message box

Hope This Help.

Please give rep if this solution helped you
 
Back
Top