I have a message box on my close command with a vbYesNoCancel thingy with it, asking the user if they want to save or not. Yes=opens save sub, No=unloads everything, Cancel=Exits sub. But I can't get the syntax right!!! Can anyone help me???
Printable View
I have a message box on my close command with a vbYesNoCancel thingy with it, asking the user if they want to save or not. Yes=opens save sub, No=unloads everything, Cancel=Exits sub. But I can't get the syntax right!!! Can anyone help me???
Here is a quick sample for you:
VB Code:
Private Sub Command1_Click() Dim ret& ret = MsgBox("Would you like to save now?", vbYesNoCancel, "Some Title") If ret = vbYes Then 'execute your SAVE proc here ElseIf ret = vbNo Then Unload Me ElseIf ret = vbCancel Then Exit Sub End If End Sub
Try this:
VB Code:
'When you press the command button named: "Command1" Private Sub Command1_Click() Dim MSG 'Show the message box with Question style and three buttons (yes , no , cancel) MSG = msgbox ("Would you like to save?", vbQuestion+vbYesNoCancel,"Confirm Save") 'Now check what was clicked If MSG = vbYes Then 'Call the save procedure that you made call Save Procedure ElseIf MSG = vbNo Then 'Unload the current form Unload Me ElseIf MSG = vbCancel Then 'Exit the Sub or the Function Exit Sub (or if you use a function and not a command click sub the use: Exit Function) End If Exit Sub
Rhino Bull don't be ungry, just explain more the next time!!!!
Hey Darky. Is there anything in your post that's different from what's in mine ???
Here's a variation since your testing just one value... the return value.
VB Code:
Select Case MsgBox("Yahoo", vbYesNoCancel, "xx") Case vbYes Debug.Print "Yes" Case vbNo Debug.Print "No" Case vbCancel Debug.Print "Cancel" End Select
1) I explain more what everything does!
2) I added <<vbQuestion>> style of msgbox.
Do you want more?
I agree with leinad31.. his/her version would be the most efficient..
Rudy
1. I am not "angry" but sure hate cross posting ...Quote:
Originally posted by DarkX_Greece
1) I explain more what everything does!
2) I added <<vbQuestion>> style of msgbox.
Do you want more?
2. No need to add some comments after while so you can say "I have more ..." - it's silly
3. vbQuestion was in question ...
4. Not from you - that's for sure ...
Not in this case ... Select Case, however, is a bit faster and it's due to indexing.Quote:
Originally posted by RudyL
I agree with leinad31.. his/her version would be the most efficient..
Rudy
Rhino, DarkX code is different. He used an untyped variable MSG instead of your typed ret&. It was probably un-intended however.
First - variable MSG is not "untyped" (where did you hear that) but VARIANT and it's not important in this case.
Second - logic is absoluetely identical and it was posted 18(!) minutes later and this does matter (this is what I call "cross posting").
Best regards.
Okay, Okay. Stop argueing already. I figured it out, and here's a solution that works every time.
VB Code:
Private Sub mnuExit_Click() Dim msg msg = MsgBox("Do you want to save before quitting?", vbYesNoCancel, "") If msg = vbYes Then mnuSave_Click ElseIf msg = vbNo Then Dim frm As Form For Each frm In Forms If Not frm.Name = Me.Name Then Unload frm End If Next frm Unload MDIForm1 FrmOpen.Show ElseIf msg = vbCancel Then Exit Sub End If End Sub
Not that it matters, but Cross Posting is when someone posts the same Thread on more than 1 forum just to try and get more responses.
Quote:
Originally posted by RhinoBull
First - variable MSG is not "untyped" (where did you hear that) but VARIANT and it's not important in this case.
Second - logic is absoluetely identical and it was posted 18(!) minutes later and this does matter (this is what I call "cross posting").
Best regards.
Makes sense to me, but I put the question up to get an answer from you people. As it is, I got the answer from my teacher!!! Something about that tells me you guys aren't doing your job....
As you can see, I was referring to Rhino's comment not yours.
But we are not here to "work" for you. Poeple just come here to help others. Next time go to your teacher first then.
And by the way, your teacher gave you the same answer Rhino did, except Rhino assumed you knew a little VB, which is obvious you don't.
I know all of the VB I need to use for the time being, thanks to my teacher. As it was, he wasn't available when I needed the answer, so I put it up here...Quote:
And by the way, your teacher gave you the same answer Rhino did, except Rhino assumed you knew a little VB, which is obvious you don't.
I'm aware of that. I was just making a comment as to why we were arguing over a friggin message box... Whatever the reason, you all have me baffled.Quote:
But we are not here to "work" for you. Poeple just come here to help others.
I would have if I could have, but I could not, so I did not.Quote:
Next time go to your teacher first then.
Yes, I can see.Quote:
As you can see, I was referring to Rhino's comment not yours.
This sort of of talk should go to a chit-chat but anyway - you're refering to DOUBLE POSTING, cross post is if I would post something identical to someoneelses solution within the same thread. :wave:Quote:
Originally posted by BrianS
Not that it matters, but Cross Posting is when someone posts the same Thread on more than 1 forum just to try and get more responses.
Something for you to know, shifter:Quote:
Originally posted by timeshifter
Makes sense to me, but I put the question up to get an answer from you people. As it is, I got the answer from my teacher!!! Something about that tells me you guys aren't doing your job....
everyone arround here (and elsewhere) is a volunteering to answer to people like you on his/her own time and is not obligated to reply what-so-ever.
And second thing is just out of curiousity: what's your teacher suggested you that I or DarkX didn't ???
I'm completely aware of that. I just think that it's kinda funny how a question about message boxes can start such an arguement.Quote:
everyone arround here (and elsewhere) is a volunteering to answer to people like you on his/her own time and is not obligated to reply what-so-ever.
Absolutely nothing. However, there was a period of time in between when I put the post up and I got my answer, and another between that time and the time I checked this forum again. So, I just got the same answer three times, but my teacher's answer happened to come first.Quote:
And second thing is just out of curiousity: what's your teacher suggested you that I or DarkX didn't ???
Nope, I'm referring to Cross Posting.
This is geared more towards Usenet groups, but also applies the same to Forums.
http://dict.die.net/cross-post/
http://www.eff.org/Net_culture/Net_i...ML/eeg_76.html
Quote:
Originally posted by RhinoBull
This sort of of talk should go to a chit-chat but anyway - you're refering to DOUBLE POSTING, cross post is if I would post something identical to someoneelses solution within the same thread. :wave:
Please don't "jump on in" unless you have something pertinent to say about VB.