end without form unload

S

Shawn

Have had a complete brain-fart and cannot think of how to stop code
execution without unloading the form in vb.net. In other words, if my
code catches an error, I want it to tell the user and stop execution
so the user can fix the error and restart the code without unloading
the app.

Shawn
 
S

Shawn

I have a form with a ton of fields to fill by the user. The entries
must fit certain criteria and that is checked during runtime. If an
entry fails a criteria the code should end and tell the user why it
stopped. However. I do not want the form to unload. If you make a
mistake typing in Word, Word does not close, it shows you the spelling
error.

Shawn
 
L

Lloyd Sheen

Shawn said:
I have a form with a ton of fields to fill by the user. The entries
must fit certain criteria and that is checked during runtime. If an
entry fails a criteria the code should end and tell the user why it
stopped. However. I do not want the form to unload. If you make a
mistake typing in Word, Word does not close, it shows you the spelling
error.

Shawn

What you want to research is Validate. Ensure that the CausesValidation
property is set to True for all fields where you want to validate. Then
handle the Validating event for the control on the form. This will fire
when you attempt to move focus to another field.

Depending on your logic you can also use the ErrorProvider for display
purposes.

LS
 
J

Jack Jackson

I have a form with a ton of fields to fill by the user. The entries
must fit certain criteria and that is checked during runtime. If an
entry fails a criteria the code should end and tell the user why it
stopped. However. I do not want the form to unload. If you make a
mistake typing in Word, Word does not close, it shows you the spelling
error.

Shawn

Where is this checking performed? If your code doesn't call the
form's Close method, the form won't close.
 
K

kimiraikkonen

I have a form with a ton of fields to fill by the user.  The entries
must fit certain criteria and that is checked during runtime.  If an
entry fails a criteria the code should end and tell the user why it
stopped.  However. I do not want the form to unload.  If you make a
mistake typing in Word, Word does not close, it shows you the spelling
error.

Shawn

As far as i understood, you want your users to be prevented from
closing their form with notifying the close reason, if so, you can use
FormClosing event handler to notify close reason with keeping form
alive when a problem occurs in your form.

In FormClosing event handler, use "e.CloseReason" enum to notify
reason, and e.Cancel = True to keep form alive.

However, based on your wish, you can also use a Try-Catch and put a
notification method in Catch like a MsgBox then your users will have
another chance to re-fill the required fields on your form.

Not sure, but i hope that gives you an idea about the pattern,

Hope this helps,

Onur Güzel
 
P

Phill W.

Shawn said:
I have a form with a ton of fields to fill by the user. The entries
must fit certain criteria and that is checked during runtime. If an
entry fails a criteria the code should end and tell the user why it
stopped.

All perfectly reasonable and there are /many/ ways to accomplish it,
practically /none/ of which involve closing the Form.
However I do not want the form to unload.

It won't; unless you tell it to.

Or ...

.... if you allow an Unhanded Exception to propagate out of your code,
causing the entire application to crash and burn.

Don't let that happen.
Anywhere the user can initiate an action (loading the form, clicking a
button, etc., etc.), you should have at least one Exception handler
(Catch block) so that there are [hopefully] /no/ unhandled Exceptions.
That way, you can deal with (i.e. handle) anything that goes wrong
unless, of course, it goes /so/ far wrong that there's probably nothing
you can do about it anyway, like an Out of Memory error.
If you make a mistake typing in Word, Word does not close,
it shows you the spelling error.

Now, now. Don't go giving Our Friends in Redmond ideas ...
They forced us to adopt "The Ribbon". Why shouldn't they insist that we
never make a single spelling miztake? ;-)

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top