Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

message box msgboxresult. not recognizing 1

Status
Not open for further replies.

lunaclover

Programmer
Joined
Jun 22, 2005
Messages
54
Hi - what in the world is wrong with this code?

Here's what is supposed to happen. When a user chooses a certain option from a combobox, and the clicks on chkBox1, a message box is supposed to come up to validate it.. it comes up when it is checked, but when I click no, or yes, it doesn't care. Here's my code.

Private Sub chkPressure_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkPressure.CheckedChanged

If chkBox1.CheckState.Checked And combobox.Text.Equals("Choice 1") Or combobox.Text.Equals("Choice 2") Then
Dim intReturnValue As Integer
If chkPressure.Checked = True Then
MsgBox("Blah blah blah. Do you still want this option?", MsgBoxStyle.YesNo + MsgBoxStyle.Information + MsgBoxStyle.SystemModal, "Message Box")
If (intReturnValue = MsgBoxResult.No) Then
chkBox1.Checked = False
End If
End If
End If
End Sub

It's supposed to uncheck it if the user says, "No" (i.e. I don't still want this option). Instead it just stays checked.

What gives?
 
MsgBox" is another one of those Microsoft.VisualBasic fluff functions.

try something like this

Dim result As DialogResult = MessageBox.Show(Me, "Selections", "Confirm Image Selections", MessageBoxButtons.YesNo)
If result = System.Windows.Forms.DialogResult.Yes Then
'Do something
ElseIf result = System.Windows.Forms.DialogResult.No
'Do something else
End If
 
It returns

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

Additional information: Cast from string "Message Box" to type 'Integer' is not valid.

I'll keep messing with it, any further help of course is welcome!
 
You could try:

Code:
        If chkBox1.CheckState.Checked And combobox.Text.Equals("Choice 1") Or combobox.Text.Equals("Choice 2") Then
            Dim intReturnValue As Integer
            If chkPressure.Checked = True Then
                [b]intReturnValue = [/b]MsgBox("Blah blah blah.  Do you still want this option?", MsgBoxStyle.YesNo + MsgBoxStyle.Information + MsgBoxStyle.SystemModal, "Message Box")
                If (intReturnValue = MsgBoxResult.No) Then
                    chkBox1.Checked = False
                End If
            End If
        End If
    End Sub

Although I agree with stsuing that it would be better to use MessageBox.

Hope this helps.
 
MsgBox returns MsgBoxResult
I don't know about MsgBoxStyle.YesNo + MsgBoxStyle.Information + MsgBoxStyle.System

What about this.

If chkBox1.Checked Andalso combobox.Text.Equals("Choice 1") Orelse combobox.Text.Equals("Choice 2") Then
Dim intReturnValue As MsgBoxResult
If chkPressure.Checked = True Then
intReturnValue = MsgBox("Blah blah blah. Do you still want this option?", CType(CInt(MsgBoxStyle.YesNo) + CInt(MsgBoxStyle.Information) + CInt(MsgBoxStyle.SystemModal), MsgBoxStyle), "Message Box")
If (intReturnValue = MsgBoxResult.No) Then
chkBox1.Checked = False
End If
End If
End If
 
Luna, do you want chkBox1 to uncheck when:

(1) chkBox1 is checked And combobox.Text = "Choice 1"
(2) chkBox1 is checked And combobox.Text = "Choice 2"
(3) chkBox1 checked status is irrelevent And combobox.Text = "Choice 2"

 
Thanks everybody! stsuing, I tried what you suggested and it worked like a charm - you are the best. Thanks earthandfire for your help too!

LunaClover

 
if a post was helpfull then we give a star. I'm in a generous mood today

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top