|
-
Mar 31st, 2004, 11:45 AM
#1
Question about MsgBox [ Resolved, but we are having a good arguement, so jump on in!]
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???
Last edited by timeshifter; Mar 31st, 2004 at 04:24 PM.
-
Mar 31st, 2004, 12:09 PM
#2
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
Last edited by RhinoBull; Mar 31st, 2004 at 12:13 PM.
-
Mar 31st, 2004, 12:27 PM
#3
Hyperactive Member
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!!!!
Last edited by DarkX_Greece; Mar 31st, 2004 at 12:56 PM.
-
Mar 31st, 2004, 12:31 PM
#4
Hey Darky. Is there anything in your post that's different from what's in mine ???
-
Mar 31st, 2004, 12:42 PM
#5
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
-
Mar 31st, 2004, 12:52 PM
#6
Hyperactive Member
1) I explain more what everything does!
2) I added <<vbQuestion>> style of msgbox.
Do you want more?
-
Mar 31st, 2004, 12:56 PM
#7
Frenzied Member
I agree with leinad31.. his/her version would be the most efficient..
Rudy
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Mar 31st, 2004, 01:02 PM
#8
Originally posted by DarkX_Greece
1) I explain more what everything does!
2) I added <<vbQuestion>> style of msgbox.
Do you want more?
1. I am not "angry" but sure hate cross posting ...
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 ...
-
Mar 31st, 2004, 01:04 PM
#9
Originally posted by RudyL
I agree with leinad31.. his/her version would be the most efficient..
Rudy
Not in this case ... Select Case, however, is a bit faster and it's due to indexing.
-
Mar 31st, 2004, 02:25 PM
#10
Hyperactive Member
Rhino, DarkX code is different. He used an untyped variable MSG instead of your typed ret&. It was probably un-intended however.
-
Mar 31st, 2004, 02:42 PM
#11
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.
-
Mar 31st, 2004, 03:04 PM
#12
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
-
Mar 31st, 2004, 03:09 PM
#13
Frenzied Member
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.
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.
-
Mar 31st, 2004, 03:15 PM
#14
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....
-
Mar 31st, 2004, 03:20 PM
#15
Frenzied Member
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.
-
Mar 31st, 2004, 03:26 PM
#16
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...
But we are not here to "work" for you. Poeple just come here to help others.
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.
Next time go to your teacher first then.
I would have if I could have, but I could not, so I did not.
As you can see, I was referring to Rhino's comment not yours.
Yes, I can see.
-
Mar 31st, 2004, 04:12 PM
#17
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.
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.
-
Mar 31st, 2004, 04:17 PM
#18
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....
Something for you to know, shifter:
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 ???
-
Mar 31st, 2004, 04:23 PM
#19
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.
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.
And second thing is just out of curiousity: what's your teacher suggested you that I or DarkX didn't ???
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.
-
Mar 31st, 2004, 04:34 PM
#20
Frenzied Member
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
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.
-
Mar 31st, 2004, 04:35 PM
#21
Please don't "jump on in" unless you have something pertinent to say about VB.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|