Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 29th, 2004, 10:12 PM   #1
mgoku21
Newbie
 
Join Date: Nov 2004
Posts: 12
Rep Power: 0 mgoku21 is on a distinguished road
I got a problem. Im confused on how to manipulate a MessageBox using an IF statment. I need it to close the program when I hit Cancel button and to run a SaveDialogBox when I hit OK. Just cant figure it out. Thanks.
mgoku21 is offline   Reply With Quote
Old Nov 29th, 2004, 11:50 PM   #2
nerdfiles
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 nerdfiles is on a distinguished road
Here is the code I have now:
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
    Dim datBalance As StreamWriter
    Dim dgrResult As DialogResult

    MessageBox.Show("Do you wish to save?", "Save?", _
      MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)

    dlgSave.InitialDirectory = Application.StartupPath
    dgrResult = dlgSave.ShowDialog()
    If dgrResult = DialogResult.OK Then
      datBalance = New StreamWriter(dlgSave.FileName)
      datBalance.WriteLine(FormatCurrency(mdecBalance, , , TriState.False))
      datBalance.Close()
    Else
      Me.Close()
    End If

    Me.Close()
  End Sub
nerdfiles is offline   Reply With Quote
Old Nov 30th, 2004, 12:44 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I suggest using YesNoCancel, where Yes saves and exits, No just exits, and Cancel stops the app from exiting.

Now, I'm not 100% sure in VB .NET, but in VB6, you need to get the return value from the message box and test it for vbYes, vbNo or vbCancel:

Dim retVal as Integer

retVal = MessageBox.Show("Do you wish to save?", "Save?", _
     MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)
If retVal = vbYes Then
   DoSaveStuff()
   Me.Close()
ElseIf retVal = vbNo Then
   Me.Close()
EndIf

That should do it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 30th, 2004, 6:08 PM   #4
nerdfiles
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 nerdfiles is on a distinguished road
Quote:
Originally posted by Ooble@Nov 30 2004, 06:44 PM
I suggest using YesNoCancel, where Yes saves and exits, No just exits, and Cancel stops the app from exiting.

Now, I'm not 100% sure in VB .NET, but in VB6, you need to get the return value from the message box and test it for vbYes, vbNo or vbCancel:

Dim retVal as Integer

retVal = MessageBox.Show("Do you wish to save?", "Save?", _
 * * * * MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)
If retVal = vbYes Then
 * * DoSaveStuff()
 * * Me.Close()
ElseIf retVal = vbNo Then
 * * Me.Close()
EndIf

That should do it.
And it did it, thanks a bunch.

I wasn't aware of the whole retVal concept.

Now I am. O_O
nerdfiles is offline   Reply With Quote
Old Dec 1st, 2004, 11:40 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Glad I could help. And unlike most of my code, I think that's bug-free as well.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Dec 7th, 2004, 5:21 AM   #6
Pino
Newbie
 
Join Date: Nov 2004
Posts: 1
Rep Power: 0 Pino is on a distinguished road
Quote:
Originally posted by nerdfiles+Dec 1 2004, 12:08 AM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (nerdfiles @ Dec 1 2004, 12:08 AM)</td></tr><tr><td id='QUOTE'> <!--QuoteBegin-Ooble@Nov 30 2004, 06:44 PM
I suggest using YesNoCancel, where Yes saves and exits, No just exits, and Cancel stops the app from exiting.

Now, I'm not 100% sure in VB .NET, but in VB6, you need to get the return value from the message box and test it for vbYes, vbNo or vbCancel:

Dim retVal as Integer

retVal = MessageBox.Show("Do you wish to save?", "Save?", _
 * * * * MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation)
If retVal = vbYes Then
 * * DoSaveStuff()
 * * Me.Close()
ElseIf retVal = vbNo Then
 * * Me.Close()
EndIf

That should do it.
And it did it, thanks a bunch.

I wasn't aware of the whole retVal concept.

Now I am. O_O [/b][/quote]
You could just do it

If MsgBox("Question", vbOKCancel, "Title") = vbOK Then
'etc etc

Pino is offline   Reply With Quote
Old Dec 8th, 2004, 12:44 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
But then you can't use Yes, No and Cancel...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 11th, 2005, 7:15 PM   #8
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Message Box

What about:
Select Case MsgBox("Do you want to lay off all your employees, Bill?", vbExclamation + vbYesNoCancel, "Microsoft Corporation")
Case VbYes
Call FireEveryone
Case VbNo
Call PayEveryoneABonus
Case VbCancel
Call FallAsleep
End Select
Rory is offline   Reply With Quote
Old Jan 12th, 2005, 9:46 AM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Stop dragging up old posts already.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:02 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC