vb.netpredefined-variables

What type of data is in MessageBoxButton.Ok and MessageBoxButton.OkCancel?


If I wanted to send either MessageBoxButtons.Ok or MessageBoxButtons.OkCancel to a MessageBox and I wanted to store the correct value in a variable, to what type should I Dim it?

Dim MyVariable As ______ 
If <condition> Then
   MyVariable = MessageBoxButtons.Ok
Else
   MyVariable = MessageBoxButtons.OkCancel
End If

MessageBox.Show("Message", "Title", MyVariable)

Solution

  • If MessageBox.Show("some text", "caption", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.OK Then
      'they picked ok
    End If
    

    Or:

    Dim result As DialogResult
    result = MessageBox.Show("some text", "caption", MessageBoxButtons.OKCancel)