How do i backout from a messagebox prompt if i select "NO"?

It's a function call, so simply check the return value.
 
This is my code. Very sorry for not making myself clear. VB6 have something called "cancel" so does VB.Net have something similar?

Sub FrmForm1Closing(ByVal sender As Object, ByVal e As EventArgs)
If MessageBox.Show("Are you sure?", "EXIT APPLICATION", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.Close
application.exit
Else
'Do something else.
End If
End sub
 
thats correct. By not putting anything in the NO "else", nothing will happen.

Change your code to;

VB.NET:
Sub FrmForm1Closing(ByVal sender As Object, ByVal e As EventArgs)
If MessageBox.Show("Are you sure?", "EXIT APPLICATION", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.Close
application.exit
End If
End sub

All I did was remove the Else line.

When you click Yes, the program closes, when you click No nothing happens and your program remains open...
 
Uh oh. It seem like you are wrong. I did what you said yet upon clicking "NO" it still closed my Login form and return back to the MDI parent form. BTW, for your information, i am using SharpDevelop and there are other sub routine beneath. I wondered if there is much diff between SharpDevelop and VB.Net
 
SharpDevelop

Sorry never heard of it....

If you click No then nothing should happen, as you've only put the clause to what to do in Yes -

i.e. .dialogresult = dialogresult.yes

Then
'do this
Else
'do this
End If

If nothing appears for Else, or if Else doesn't even appear in the code, nothing will happen when No is pressed.

You must have a conflict with another part of your code on that form.
 
VB6 have this "cancel" option whereby further processing will be stop and the current form will not be closed
 
Think about the logic:

If the person says YES, you do NOTHING - let the app close
If they say NO, you cancel the close event:

VB.NET:
FormClosing

  If MessageBox.Show("Sure to quit?", "", MessageBoxButtons.YesNo) == DialogResult.No
    e.Cancel = True 'set the event cancel property to prevent app exiting
  End If

End FormClosing
 
Sample coding only
------------------

private sub Logic()
if yes then
do something
else
do nothing
endif
'REM NOTE THE LINE BELOW PLS
print "still doing something"
end sub

NOW
If i run the program and click "NO" the statement "Still doing something" will be processed

I recalled when using VB6 that there is a cancel and a "Exit Sub" or "Exit Function" command. So if i now replace the "do nothing" line to as below then the "Still doing something" will be skip. UC

if yes then
do something
else
EXIT SUB
endif
print "Still doing something"
end sub
 
I think the problem i am now facing as i am now using SharpDevelop is to figure out what command to use to break the routine instead of letting it flow thru. That all
 
i suggest that you guys stop thinking about this as soon as possible.

when it comes to the form's closing event you guys have your logic all wrong

cjard has posted the correct login for the closing event
 
I recalled when using VB6

There's a phrase that goes something like "Drop the dead donkey"

This isnt VB6, dont treat it like it is. Dont try to solve problems in VB6 ways


FormClosing fires when your form is closing. Thats a fact. You cannot change it. If the user does NO want to close then you must cancel the close which is already in progress.
If the user does not want to run over the old lady crossing the road, he must put on the brakes. Its no good wishing the car wasnt moving because it already is

that there is a cancel and a "Exit Sub" or "Exit Function" command.
Exit Sub simply exits the sub. If you jump out the car before you run over the old lady, the car still runs over the old lady.
 
Dear mr Cjard.
I believed you must be a very busy guy else you should have realised that the "cancel" property was what were on my mind in the first place. It just that i do not know where to invoke it.

BTW, the "exit sub" will truly exit the sub and will not run over the old lady crossing the road. Believed me
 
Back
Top