Page 1 of 2 12 LastLast
Results 1 to 40 of 45

Thread: Simple msgbox cmd

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136

    Question Simple msgbox cmd

    Ok i made a msgbox like this.

    Private Sub Command1_Click()
    MsgBox "Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?"
    End Sub

    So when i clcik cmd 1 that comes up with the yes or no option. How can i make it so that when no is clicked nothing happens and when yes is clicked it exicutes the unload me command?

    Sorry if this is basic but i'm a newbie

    Thanks in advance

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    VB Code:
    1. Private Sub Command1_Click()
    2.     Select Case MsgBox("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")
    3.         Case vbYes
    4.             End
    5.         Case vbNo
    6.             Exit Sub
    7.     End Select
    8. End Sub

  3. #3
    DaoK
    Guest
    VB Code:
    1. Private Sub Command1_Click()
    2. If (MsgBox("Unload me ?", vbQuestion + vbYesNo, "Welcome")) = vbYes Then
    3.     Unload Me
    4. End If
    5. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Thanks for your replys

  5. #5
    DaoK
    Guest
    No problem

  6. #6
    Fanatic Member Kings's Avatar
    Join Date
    Aug 2001
    Posts
    673
    Could this work?

    Dim MBox as String


    MBox = MsgBox "Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?"

    If MBox = vbYes Then
    Unload Me
    Else
    'do nothing
    End If
    K i n g s

  7. #7
    If there were ()s around the MsgBox command, then yes.

  8. #8
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    The code would work, but MsgBox as a function actually returns an Integer and not a string.

  9. #9
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    VB Code:
    1. MSGRetVal = MSGBox("Are you sure you want to exit?", 36, "Unload Me?")
    2. Select Case MSGRetVal
    3. Case 6
    4. Unload me
    5. Case 7
    6. 'nothing
    7. End Select

    thats what i use i just use the vb4 message box builder thing to do mine and then declare MSGRetVal as a string

  10. #10
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    VB Code:
    1. MSGRetVal as string
    2.  
    3. Command1_Click()
    4. MSGRetVal = MSGBox("Are you sure you want to exit?", 36, "Unload Me?")
    5. Select Case MSGRetVal
    6. Case 6
    7. Unload me
    8. Case 7
    9. 'nothing
    10. End Select

    thats what i use i just use the vb4 message box builder thing to do mine and then declare MSGRetVal as a string

  11. #11
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    VB Code:
    1. MSGRetVal as string
    The code would work, but MsgBox as a function actually returns an Integer and not a string.
    vbYes and vbNo are instrinsic constants that equal 6 and 7 and help make the code a bit more readable.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Thanks for all your replies

  13. #13
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    You'll be starting to wish you hadn't asked the question at this rate!

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Kings your one didnt work well i kept getting an error.

  15. #15
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    As Filburt1 said, you need brackets when you want MsgBox to return an Integer:

    VB Code:
    1. ' Wrong
    2. MBox = MsgBox "Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?"
    3.  
    4. ' Correct
    5. MBox = MsgBox ("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")

  16. #16
    Fanatic Member Kings's Avatar
    Join Date
    Aug 2001
    Posts
    673
    gav, it does work but there was 1 little mistake
    here, now it does work


    Dim MBox As Integer


    MBox = MsgBox("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")

    If MBox = vbYes Then
    Unload Me
    Else
    'do nothing
    End If
    End Sub
    K i n g s

  17. #17
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    rudgej:
    thats just what i use for stuff like that works fine for me

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Oh ok now kings works :P

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Also is there any other decent things i can do with msg boxes like set off cmd buttons with them.

  20. #20
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    What do you mean? If you wanted to run code associated with a command button, then you could just call the command button's code:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Select Case MsgBox("Run Command2 code?", vbQuestion + vbYesNo, "Well?")
    3.         Case vbYes
    4.             Command2_Click
    5.         Case vbNo
    6.             Exit Sub
    7.     End Select
    8. End Sub

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Oh yeah sorry i was thinking to complex.

    Hmmm i am stupid.

    Thanks anyway rudgej

  22. #22
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    do u mean like when u click a button i meassge box come up?

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Nope.

    I meant when you have a msg box saying do you want to do this yes or no.

    If you click yes it will call a command button. My mind just went blank and forgot how thats all.Ruds post reminded me

  24. #24
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Originally posted by Kings
    gav, it does work but there was 1 little mistake
    here, now it does work


    Dim MBox As Integer


    MBox = MsgBox("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")

    If MBox = vbYes Then Unload Me

    Else
    'do nothing
    End If

    End Sub
    the red part is not needed

  25. #25
    DaoK
    Guest
    the red part is not needed

    really???? lol who dont know that

  26. #26
    DaoK
    Guest
    I posted that ( the 3rd post in tha thread ):

    VB Code:
    1. Private Sub Command1_Click()
    2. If (MsgBox("Unload me ?", vbQuestion + vbYesNo, "Welcome")) = vbYes Then
    3.     Unload Me
    4. End If
    5. End Sub

    And it work perfectly....why all still continue to try to find a way with variable ?

  27. #27
    Tradition, I guess, in more ways than one.

  28. #28
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Originally posted by DaoK



    really???? lol who dont know that
    Cool Off. The one who asked the question doesn't know.

  29. #29
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    why not use mine

  30. #30
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    or quick and simple:
    VB Code:
    1. If MsgBox ("Quit or no huh?", vbYesNo) = vbyes then unload me else exit sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  31. #31

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    Thanks all

    I like that short and simple way thats kool.

  32. #32
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It's true that the MsgBox function returns an Integer. To be more exact it returns an Integer from the VbMsgBoxResult enumeration so you could declare the return value with this type.
    VB Code:
    1. Dim mbr As VbMsgBoxResult
    2.     mbr = MsgBox("I ask you a question and what do you respond", vbYesNo)
    Just type If mbr= and the possible responses pops up in a list.

  33. #33

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    kool thx joacim.

  34. #34
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Question

    On a side note, ..... has anyone ever made their own MessageBox?

    Not using the MsgBox command, but with an actual form and icons?
    ~Peter


  35. #35
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Yes I have one that allows a checkbox at the bottom, I use it frequently to add MsgBox with a "Don't tell me this again" message in the checkbox.

  36. #36
    DaoK
    Guest
    Cool Off. The one who asked the question doesn't know.
    'nothing = nothing = not needed, I am a poor french canadian and I know that

  37. #37
    Junior Member
    Join Date
    Jun 2001
    Location
    india
    Posts
    16

    Hey!you

    It is as easy as you:

    Private Sub Command1_Click()
    action=MsgBox("Are you sure you want to exit?", Question + vbYesNo, "Exit?")
    if action=vbyes then end
    End Sub

  38. #38
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    yep sure is......but mine beeps LOL

  39. #39

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    136
    ok.
    -----------------------------------------------
    Gavin is a newbie at programming and knows almost nothing
    -----------------------------------------------

  40. #40
    DaoK
    Guest
    but mine beeps LOL

    wowowow

Page 1 of 2 12 LastLast

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