Exit Event

Discussion in 'AutoCAD' started by Randy Richardson, Apr 23, 2004.

  1. I have 2 questions about the Exit Event.

    If I want the program to take a certain action before leaving a particular
    control, say control "Xyz", I create a sub Xyz_Exit.

    This sub automatically runs whenever the user leaves control "Xyz."
    Therefore, it is not a sub that would be explicitly called within the
    program, but rather a sub that is automatically fired when the user takes a
    certain action. That being the case, how would I go about supplying
    arguments to this sub? The "help" file says that I should assign the value
    of True to the Cancel argument if I want the focus to stay on the control,
    but I could find no example of how to do that.

    Is there any way for the Exit Event to supply to the program the reason that
    the control is being exited? For example, if the user were to press the
    "Cancel" button on the dialog box, while in control "Xyz" it would not be
    desirable to run function Xyz_Exit, but if the user leaves the control for
    any other reason than it would be. If there were a way for the program to
    see the intended destination before running, that would be great. I realize
    that I could, instead of using the Exit Event on control "Xyz" I could
    instead add an Enter Event on every control except control "Xyz" and the
    Cancel button, but with the large number of controls on my dialog box that
    would be a big job, particularly since the "Xyz" control is far from the
    only one that requires this type of treatment.

    I realize that the wisdom of doing it this way can be debated, but rather
    than having that debate I would just like to have an answer to my technical
    questions. I'm not the one who decides exactly how the dialog box should
    work, so I am not in a position to respond to your misgivings. Frankly, I
    have them too. So I'm just requesting help from anyone with the needed
    knowledge that would be kind enough to help.

    Thank you,

    Randy
     
    Randy Richardson, Apr 23, 2004
    #1
  2. Thanks, Ed.

    I do have that cancel = true line, and now it seems to be working without
    the additional code that I added to return focus to the control. Either my
    memory is blurry or I've changed something else, because it seemed that I
    originally had to add lines that returned focus to the control but now it
    appears they are not necessary.

    Naturally, this question was not the one that I was most concerned about,
    unfortunately. If someone could tackle my other question for me I would
    very much appreciate it. Specifically, how could I modify the code that Ed
    supplied so that it does not bring up the message box if the user has
    selected the "Cancel" button?
     
    Randy Richardson, Apr 23, 2004
    #2
  3. Randy Richardson

    Ed Jobe Guest

    You could have the cancel button set a form level boolean var and AND that
    with the test I gave you.
    In Cancel button's click event:
    blnCancelForm = True

    Then the following will happen only when the Cancel button hasn't been
    pressed.
    If Test1 = "" And blnCancelForm = False Then
     
    Ed Jobe, Apr 23, 2004
    #3
  4. I tried that and it didn't work for me, but even so it has become clear that
    your answer is correct. It answers the exact question I asked. The problem
    is, the reason it didn't work for me is that I also use an AfterUpdate event
    that is very similar to the Exit event. The fix that you proposed works for
    the Exit event, but not for the AfterUpdate event because the AfterUpdate
    event fires before the Cancel button's Click event.

    I'll start a new thread with the corrected question.

    Thank you, Ed. You have been very helpful.

    -Randy
     
    Randy Richardson, Apr 23, 2004
    #4
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 (here). After that, you can post your question and our members will help you out.