-
Sep 23rd, 2001, 12:05 PM
#1
Thread Starter
Addicted Member
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
-
Sep 23rd, 2001, 12:11 PM
#2
Hyperactive Member
VB Code:
Private Sub Command1_Click()
Select Case MsgBox("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")
Case vbYes
End
Case vbNo
Exit Sub
End Select
End Sub
-
Sep 23rd, 2001, 12:12 PM
#3
VB Code:
Private Sub Command1_Click()
If (MsgBox("Unload me ?", vbQuestion + vbYesNo, "Welcome")) = vbYes Then
Unload Me
End If
End Sub
-
Sep 23rd, 2001, 12:16 PM
#4
Thread Starter
Addicted Member
Thanks for your replys
-
Sep 23rd, 2001, 12:18 PM
#5
No problem
-
Sep 23rd, 2001, 12:53 PM
#6
Fanatic Member
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
-
Sep 23rd, 2001, 12:56 PM
#7
Member
If there were ()s around the MsgBox command, then yes.
-
Sep 23rd, 2001, 12:59 PM
#8
Hyperactive Member
The code would work, but MsgBox as a function actually returns an Integer and not a string.
-
Sep 23rd, 2001, 01:04 PM
#9
Frenzied Member
VB Code:
MSGRetVal = MSGBox("Are you sure you want to exit?", 36, "Unload Me?")
Select Case MSGRetVal
Case 6
Unload me
Case 7
'nothing
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
-
Sep 23rd, 2001, 01:05 PM
#10
Frenzied Member
VB Code:
MSGRetVal as string
Command1_Click()
MSGRetVal = MSGBox("Are you sure you want to exit?", 36, "Unload Me?")
Select Case MSGRetVal
Case 6
Unload me
Case 7
'nothing
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
-
Sep 23rd, 2001, 01:09 PM
#11
Hyperactive Member
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.
-
Sep 23rd, 2001, 01:10 PM
#12
Thread Starter
Addicted Member
Thanks for all your replies
-
Sep 23rd, 2001, 01:11 PM
#13
Hyperactive Member
You'll be starting to wish you hadn't asked the question at this rate!
-
Sep 23rd, 2001, 01:11 PM
#14
Thread Starter
Addicted Member
Kings your one didnt work well i kept getting an error.
-
Sep 23rd, 2001, 01:15 PM
#15
Hyperactive Member
As Filburt1 said, you need brackets when you want MsgBox to return an Integer:
VB Code:
' Wrong
MBox = MsgBox "Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?"
' Correct
MBox = MsgBox ("Are you sure you want to exit?", vbQuestion + vbYesNo, "Exit?")
-
Sep 23rd, 2001, 01:17 PM
#16
Fanatic Member
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
-
Sep 23rd, 2001, 01:58 PM
#17
Frenzied Member
rudgej:
thats just what i use for stuff like that works fine for me
-
Sep 23rd, 2001, 02:05 PM
#18
Thread Starter
Addicted Member
-
Sep 23rd, 2001, 02:07 PM
#19
Thread Starter
Addicted Member
Also is there any other decent things i can do with msg boxes like set off cmd buttons with them.
-
Sep 23rd, 2001, 02:10 PM
#20
Hyperactive Member
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:
Private Sub Command1_Click()
Select Case MsgBox("Run Command2 code?", vbQuestion + vbYesNo, "Well?")
Case vbYes
Command2_Click
Case vbNo
Exit Sub
End Select
End Sub
-
Sep 23rd, 2001, 02:12 PM
#21
Thread Starter
Addicted Member
Oh yeah sorry i was thinking to complex.
Hmmm i am stupid.
Thanks anyway rudgej
-
Sep 23rd, 2001, 02:23 PM
#22
Frenzied Member
do u mean like when u click a button i meassge box come up?
-
Sep 23rd, 2001, 02:28 PM
#23
Thread Starter
Addicted Member
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
-
Sep 23rd, 2001, 08:15 PM
#24
Frenzied Member
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
-
Sep 23rd, 2001, 08:20 PM
#25
the red part is not needed
really???? lol who dont know that
-
Sep 23rd, 2001, 08:22 PM
#26
I posted that ( the 3rd post in tha thread ):
VB Code:
Private Sub Command1_Click()
If (MsgBox("Unload me ?", vbQuestion + vbYesNo, "Welcome")) = vbYes Then
Unload Me
End If
End Sub
And it work perfectly....why all still continue to try to find a way with variable ?
-
Sep 23rd, 2001, 08:22 PM
#27
Member
Tradition, I guess, in more ways than one.
-
Sep 23rd, 2001, 08:32 PM
#28
Frenzied Member
Originally posted by DaoK
really???? lol who dont know that
Cool Off. The one who asked the question doesn't know.
-
Sep 23rd, 2001, 09:05 PM
#29
Frenzied Member
-
Sep 23rd, 2001, 10:38 PM
#30
The picture isn't missing
or quick and simple:
VB Code:
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 .
-
Sep 24th, 2001, 10:21 AM
#31
Thread Starter
Addicted Member
Thanks all
I like that short and simple way thats kool.
-
Sep 24th, 2001, 10:29 AM
#32
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:
Dim mbr As VbMsgBoxResult
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.
-
Sep 24th, 2001, 10:32 AM
#33
Thread Starter
Addicted Member
-
Sep 24th, 2001, 11:34 AM
#34
Frenzied Member
On a side note, ..... has anyone ever made their own MessageBox?
Not using the MsgBox command, but with an actual form and icons?
~Peter
-
Sep 25th, 2001, 02:55 AM
#35
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.
-
Sep 25th, 2001, 05:32 AM
#36
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
-
Sep 25th, 2001, 07:12 AM
#37
Junior Member
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
-
Sep 27th, 2001, 11:46 AM
#38
Frenzied Member
yep sure is......but mine beeps LOL
-
Sep 27th, 2001, 12:03 PM
#39
Thread Starter
Addicted Member
-----------------------------------------------
Gavin is a newbie at programming and knows almost nothing
-----------------------------------------------
-
Sep 27th, 2001, 02:06 PM
#40
wowowow
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
|