end without form unload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn

    end without form unload

    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
  • Patrice

    #2
    Re: end without form unload

    A bit unclear. You can't both "stop code execution" and do that "without
    unloading the application".

    Or do you mean that your application code should just go out of its usual
    flow (using try/catch ? by handling unhandled exceptions ?) before resuming
    its usual flow...

    If you want to restart I believe there is also a Application.res tart method
    that relaunch the application in a clean state.

    As a side note be wise with that as trying to keep running whatever is the
    error you get is IMO not necessarily always a good idea (it can make things
    worse).

    --
    Patrice


    "Shawn" <saquisenberry@ gmail.coma écrit dans le message de groupe de
    discussion :
    1ffdc74f-60f0-4538-a754-9b43e3b1f5ee...l egroups.com...
    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

    Comment

    • Shawn

      #3
      Re: end without form unload

      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

      Comment

      • Patrice

        #4
        Re: end without form unload

        Sorry, your description make me thought you wanted to handle critical
        errors.

        Just use MessageBox.Show
        (http://msdn.microsoft.com/en-us/libr...ebox.show.aspx)
        to show a message to the user or you could use the ErrorProvider object to
        display an error icon next to all erroneous fields
        (http://msdn.microsoft.com/en-us/libr...provider.aspx).

        --
        Patrice

        "Shawn" <saquisenberry@ gmail.coma écrit dans le message de groupe de
        discussion :
        8e8f77ef-0b43-47d1-b5ca-35f5cf92208b...l egroups.com...
        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

        Comment

        • Lloyd Sheen

          #5
          Re: end without form unload


          "Shawn" <saquisenberry@ gmail.comwrote in message
          news:8e8f77ef-0b43-47d1-b5ca-35f5cf92208b@v3 9g2000pro.googl egroups.com...
          >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 CausesValidatio n
          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

          Comment

          • kimiraikkonen

            #6
            Re: end without form unload

            On Nov 18, 8:37 pm, Shawn <saquisenbe...@ gmail.comwrote:
            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.CloseRea son" 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

            Comment

            • Jack Jackson

              #7
              Re: end without form unload

              On Tue, 18 Nov 2008 10:37:15 -0800 (PST), Shawn
              <saquisenberry@ gmail.comwrote:
              >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.

              Comment

              • Phill W.

                #8
                Re: end without form unload

                Shawn wrote:
                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.

                Comment

                Working...