MessageBoxButtons.OKCancel

Arg81

Well-known member
Joined
Mar 11, 2005
Messages
949
Location
Midlands, UK
Programming Experience
1-3
Hi All,

It's been a while since I've been on here, haven't really been upto much development....

Here's my problem. I'm asking the user for a simple input via a messagebox.

My code is:

VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2]DsSearchDWR1.DWR.Clear()
daDWR.SelectCommand.Parameters("@DWRNumber").Value = txtDWRNumber.Text
daDWR.Fill(DsSearchDWR1)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] DsSearchDWR1.DWR.Rows.Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "1" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]lblStatus.Text = "Active"
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]lblStatus.Text = "Complete"
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("DWR Not Found!")
txtDWRNumber.Text = ""
txtDWRNumber.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "2" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = MessageBoxButtons.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]'Do This & Do That[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End If[/COLOR][/SIZE]

When I press the load button after entering the ID number into the textbox,
I get an error message of ;
Enum argument value 64 is not valid for buttons. buttons should be a value from DialogResult.
Parameter name: buttons

Basically what I am trying to do is create a form to allow the user to change a status of a record.
Once loaded, I want to inform the user via messagebox what the status currently is, and if they press OK, then it changes the Status, and if they press cancel then it resets the form.

Thanks for any info,
Regards
Luke
 
Hi

Change the line

VB.NET:
If MessageBox.Show(" ... ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) =MessageBoxButtons.OK then ...
to

VB.NET:
If MessageBox.Show(" ... ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) then ...
and it should (hopefully) work.

Read MSDN for a deeper understanding of MessageBox class. :)
 
OK. Well your clue is in the needed DialogResult enumeration.

try

VB.NET:
If lblStatusID.Text = "2" Then

Dim result As DialogResult
result = MessageBox.Show(... ... )
If result = DialogResult.OK Then....
' Do This
' Do That
End If


Hope this helps you :)
 
Hello mate,

I still get the same error message, it's strange as I've done it before but I haven't done anything for the last couple of months so I need to refresh my memory with programming.

Here is my full code for the btn_Load as it currently stands

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnLoad_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnLoad.Click[/SIZE]
[SIZE=2]
DsSearchDWR1.DWR.Clear()
daDWR.SelectCommand.Parameters("@DWRNumber").Value = txtDWRNumber.Text
daDWR.Fill(DsSearchDWR1)
 
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] DsSearchDWR1.DWR.Rows.Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "1" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]  lblStatus.Text = "Active"
[/SIZE][SIZE=2][COLOR=#0000ff]  Else
[/COLOR][/SIZE][SIZE=2]  lblStatus.Text = "Complete"
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]  MessageBox.Show("DWR Not Found!")
   txtDWRNumber.Text = ""
   txtDWRNumber.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "1" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] result [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DialogResult
result = MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to ACTIVE, are you sure you want to mark this DWR as COMPLETE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
[/SIZE][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] result = DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]  lblStatusID.Text = "2"
   lblStatus.Text = "Complete"
   gbComplete.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]  MessageBox.Show("Please set the Complete Date", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
   btnLoad.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]  btnClose.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]  Else
[/COLOR][/SIZE][SIZE=2]  DsSearchDWR1.Clear()
   txtDWRNumber.Text = ""
   lblStatus.Text = ""
   txtDWRNumber.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "2" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] result [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DialogResult
result = MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
[/SIZE][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] result = DialogResult.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]  lblStatusID.Text = "1"
   lblStatus.Text = "Active"
   UpdateDataSet()
   MessageBox.Show("DWR is now set to ACTIVE", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
[/SIZE][SIZE=2][COLOR=#0000ff]  Else
[/COLOR][/SIZE][SIZE=2]  DsSearchDWR1.Clear()
   txtDWRNumber.Text = ""
   lblStatus.Text = ""
   txtDWRNumber.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

 
Code...

VB.NET:
        If MsgBox("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", vbOKCancel, "Confirm") = vbOK Then
            lblStatusID.Text = "1"
            lblStatus.Text = "Active"
            UpdateDataSet()
            MessageBox.Show("DWR is now set to ACTIVE", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            DsSearchDWR1.Clear()
            txtDWRNumber.Text = ""
            lblStatus.Text = ""
            txtDWRNumber.Focus()
        End If


Same as everyone else, 'cept I put "confirm" at the top of the message box.
 
V-B_New-B said:
Hi All,

It's been a while since I've been on here, haven't really been upto much development....

Here's my problem. I'm asking the user for a simple input via a messagebox.

My code is:

VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2]DsSearchDWR1.DWR.Clear()
daDWR.SelectCommand.Parameters("@DWRNumber").Value = txtDWRNumber.Text
daDWR.Fill(DsSearchDWR1)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] DsSearchDWR1.DWR.Rows.Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "1" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]lblStatus.Text = "Active"
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]lblStatus.Text = "Complete"
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("DWR Not Found!")
txtDWRNumber.Text = ""
txtDWRNumber.Focus()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] lblStatusID.Text = "2" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = MessageBoxButtons.OK [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]'Do This & Do That[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End If[/COLOR][/SIZE]
When I press the load button after entering the ID number into the textbox,
I get an error message of ;
Enum argument value 64 is not valid for buttons. buttons should be a value from DialogResult.
Parameter name: buttons

Basically what I am trying to do is create a form to allow the user to change a status of a record.
Once loaded, I want to inform the user via messagebox what the status currently is, and if they press OK, then it changes the Status, and if they press cancel then it resets the form.

Thanks for any info,
Regards
Luke

this part:
VB.NET:
If lblStatusID.Text = "2" Then
  If MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = MessageBoxButtons.OK Then
  'Do This & Do That
  End If
End If

should be:
VB.NET:
If lblStatusID.Text = "2" Then
  Dim dlgResult As DialogResult MessageBox.Show("DWR No " & txtDWRNumber.Text & " is currently set to COMPLETE, are you sure you want to change this status to ACTIVE?", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
  Select Case dlgResult
    Case DialogResult.Ok
      'Code here for OK
    Case DialogResult.Cancel
      'Code here for Cancel
  End Select
End If
 
I figured out what the problem was - because I had not put a caption in, or put "" for a blank caption.
So instead of .show("blah blah", MessageBoxButtons.OKCancel) I used .show("blah blah", "", MessageBoxButtons.OKCancel)

All works OK as expected - thanks to everyone for your help.
Luke
 
Back
Top