Results 1 to 21 of 21

Thread: Question about MsgBox [ Resolved, but we are having a good arguement, so jump on in!]

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Question 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.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Here is a quick sample for you:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim ret&
    3.     ret = MsgBox("Would you like to save now?", vbYesNoCancel, "Some Title")
    4.     If ret = vbYes Then
    5.         'execute your SAVE proc here
    6.     ElseIf ret = vbNo Then
    7.         Unload Me
    8.     ElseIf ret = vbCancel Then
    9.         Exit Sub
    10.     End If
    11. End Sub
    Last edited by RhinoBull; Mar 31st, 2004 at 12:13 PM.

  3. #3
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315
    Try this:

    VB Code:
    1. 'When you press the command button named: "Command1"
    2. Private Sub Command1_Click()
    3.  
    4. Dim MSG
    5. 'Show the message box with Question style and three buttons (yes , no , cancel)
    6. MSG = msgbox ("Would you like to save?", vbQuestion+vbYesNoCancel,"Confirm Save")
    7. 'Now check what was clicked
    8. If MSG = vbYes Then
    9. 'Call the save procedure that you made  
    10. call Save Procedure
    11. ElseIf MSG = vbNo Then
    12. 'Unload the current form
    13.    Unload Me
    14. ElseIf MSG = vbCancel Then
    15. 'Exit the Sub or the Function
    16.    Exit Sub (or if you use a function and not a command click sub the use: Exit Function)
    17. End If
    18.  
    19. 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.
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Hey Darky. Is there anything in your post that's different from what's in mine ???

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Here's a variation since your testing just one value... the return value.

    VB Code:
    1. Select Case MsgBox("Yahoo", vbYesNoCancel, "xx")
    2.    Case vbYes
    3.       Debug.Print "Yes"
    4.    Case vbNo
    5.       Debug.Print "No"
    6.    Case vbCancel
    7.       Debug.Print "Cancel"
    8.    End Select

  6. #6
    Hyperactive Member DarkX_Greece's Avatar
    Join Date
    Jan 2004
    Location
    Athens (Greece)
    Posts
    315
    1) I explain more what everything does!
    2) I added <<vbQuestion>> style of msgbox.
    Do you want more?
    Short CV:
    1. Visual Basic 6 Programmer
    2. Web Expert


    Botonakis Web Services

  7. #7
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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 ...

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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.

  10. #10
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    The Big D
    Posts
    310
    Rhino, DarkX code is different. He used an untyped variable MSG instead of your typed ret&. It was probably un-intended however.

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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.

  12. #12

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Okay, Okay. Stop argueing already. I figured it out, and here's a solution that works every time.


    VB Code:
    1. Private Sub mnuExit_Click()
    2.  
    3.     Dim msg
    4.  
    5.     msg = MsgBox("Do you want to save before quitting?", vbYesNoCancel, "")
    6.         If msg = vbYes Then
    7.             mnuSave_Click
    8.         ElseIf msg = vbNo Then
    9.             Dim frm As Form
    10.             For Each frm In Forms
    11.                 If Not frm.Name = Me.Name Then
    12.                     Unload frm
    13.                 End If
    14.             Next frm
    15.             Unload MDIForm1
    16.             FrmOpen.Show
    17.         ElseIf msg = vbCancel Then
    18.             Exit Sub
    19.         End If
    20.  
    21. End Sub

  13. #13
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    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.

  14. #14

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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....

  15. #15
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    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.

  16. #16

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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.

  17. #17
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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.

  18. #18
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    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 ???

  19. #19

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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.

  20. #20
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    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.

  21. #21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width