|
-
Feb 25th, 2006, 04:53 PM
#1
Thread Starter
Lively Member
MSGBOX help
Hi, I was wondering how you could get a message box with a yes and no option to work. I know how to get the message box to come up, just don't understand how to make it so if they click no, then nothing happens and if they click yes then it will close.
Private Sub mnuexit_Click()
msgbox "Are you sure you want to quit?", vbyesno
End
End Sub
With that code if you click no or yes it will close both times. Wondering how to make it so if you hit no nothing happens.
Thanks
-
Feb 25th, 2006, 04:55 PM
#2
Re: MSGBOX help
VB Code:
Private Sub mnuexit_Click()
If MsgBox("Are you sure you want to quit?", vbYesNo) = vbYes Then Unload Me
End Sub
you shouldn't use End to quit your application
-
Feb 25th, 2006, 04:56 PM
#3
Thread Starter
Lively Member
Re: MSGBOX help
I usually use Unload FormMain or something like that, but I was just tring out different ways.
Thanks
-
Feb 25th, 2006, 04:58 PM
#4
Thread Starter
Lively Member
Re: MSGBOX help
Why not though? I don't see much of a difference.
-
Feb 25th, 2006, 05:05 PM
#5
Re: MSGBOX help
 Originally Posted by Grant1377
Why not though? I don't see much of a difference.
End doesn't let the application shut itself down. It's kind of like pulling the plug on your stereo. Unload [form] lets the application clean up after itself. It's more like stopping the CD player, then hitting the power button.
-
Feb 25th, 2006, 05:09 PM
#6
Re: MSGBOX help
 Originally Posted by MSDN
The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.
The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.
i didn't think it freed up the memory, but apparently it does. But, yes, it is unadvised.
-
Feb 25th, 2006, 06:20 PM
#7
-
Feb 25th, 2006, 10:39 PM
#8
Junior Member
Re: MSGBOX help
Back to the topic of the message boxes:
when you do something like:
VB Code:
msgbox("Do you want to quit?", vbyesno)
you need to use a variable, because using the "vbyesno" part means that the computer will record whether the user clicks "yes" or "no" so basically
VB Code:
dim Click as Integer
Click = msgbox("Do you want to quit?", vbyesno)
if click = vbyes then
unload me 'or end, for this part just look at the above post
end if
basically, the button the user clicks returns a 1 or a 0, I think, but i'm not sure, that 1 means yes. Either way, whichever one is returned is stored in the "click" variable, then the if statement checks what's in "Click",
if the user clicked yes, it would unload the form, otherwise, it would simply close the msgbox and do nothing else.
-
Feb 25th, 2006, 10:56 PM
#9
Re: MSGBOX help
Here are the possible button arguments
Code:
Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1 0 First button is default.
vbDefaultButton2 256 Second button is default.
vbDefaultButton3 512 Third button is default.
vbDefaultButton4 768 Fourth button is default.
vbApplicationModal 0 Application modal; the user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.
vbMsgBoxHelpButton 16384 Adds Help button to the message box
VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window
vbMsgBoxRight 524288 Text is right aligned
vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems
And the return values
Code:
Constant Value Description
vbOK 1 OK
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No
-
Feb 26th, 2006, 06:12 AM
#10
Re: MSGBOX help
@ Scriptor: hadn't i already said that in post #2?
-
Feb 26th, 2006, 07:46 AM
#11
Hyperactive Member
Re: MSGBOX help
I do in this way this, maybe a bit more need write, but i have larger possibilities – I think so.
VB Code:
If Your_variable= 1 Then
Other_variable = MsgBox( _
Prompt:=" Are you sure you want to change settings during calculation? _
Title:=" Unexpected change of settings!!", _
Buttons:=vbYesNo + vbQuestion)
If Other_variable = vbYes Then
Call cmdWrite_Click
OptLook.Value = True
Else
Exit Sub
End If
End If
I use these constants here: If constant = 6 is for vbYes and if constant = 7 is for vbNo
I assign variable constans and in this way I can realize close MsgBoxes without realization any operation
I think that it about this walked
I know, I know, my English is bad, sorry .....
-
Feb 26th, 2006, 04:00 PM
#12
Member
Re: MSGBOX help
VB Code:
Dim Msg$
Msg = MsgBox("What ever you want the messege box to say", vbYesNo, "Title")
Select Case Msg
Case vbYes
'code here
Case vbNo
'code here
End Select
God told me to skin u alive
-
Feb 26th, 2006, 04:23 PM
#13
Junior Member
Re: MSGBOX help
 Originally Posted by bushmobile
@ Scriptor: hadn't i already said that in post #2?
Yeah, I know, sorry bout that, only noticed it after I posted mine, still, I explained what happens in the code, didn't I?
-
Mar 11th, 2006, 08:51 AM
#14
Re: MSGBOX help
try this.
VB Code:
Dim Result As VbMsgBoxResult
Result = MsgBox("Are you sure you want to exit?", vbYesNo)
If (Result = vbYes) Then
Unload Me
Else
Exit Sub
End If
-
Mar 11th, 2006, 08:55 AM
#15
Re: MSGBOX help
this question was answered a fortnight ago in posts #2, #8, #11, #12 - think he's got his answer
-
Mar 11th, 2006, 10:51 AM
#16
Addicted Member
Re: MSGBOX help
dim m as variable
m=msgbox("do you want to continue?"),vbquestion+vbyesno,"continue")
if m=vbyes then
the thing you want to do
end if
if m=vbno then
end if
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
|