Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Creating an Event Procedure
◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
Creating an Event Procedure
■ The code you write to respond to form or control events is called an
"event procedure." Each object (form or control) has a set of predefined
events that it can recognize. You write event procedures only for those
events for which you want a form or control to respond.
See: ◄Controls Summary► ◄Object Events Summary►
■ Form modules are private: event and general procedures contained within
cannot be called from external modules or procedures. In addition, form
modules do not allow executable code at the model level. Code modules, on
the other hand, are public: general procedures contained within can be
called from other modules or procedures. Executable code is allowed at
the module level of code modules.
■ To define an event procedure for a form or control:
1. From the Edit menu, choose Event Procedures
2. Select the target form or control
3. Select the event you wish to write code for
4. Choose Edit in Active or Edit in New
5. Enter the code you want in the template provided
Follow Basic guidelines for entering and editing code and declarations.
See: ◄Guidelines for Entering and Editing Code►
6. Repeat steps 2 to 4 as necessary to write additional event procedures
■ Use this syntax to write an event procedure:
SUB objectname_eventname (parameters)
local variable and constant definitions
statements
END SUB
■ Instead of using the template provided by Visual Basic, you can also
create an event procedure by choosing New Sub from the Edit menu.
■ If you change the CtlName of a control after writing a procedure for it,
you must also change the name of the procedure to match the name of the
control. Otherwise, Visual Basic won't be able to match the control to
the procedure.
See: ◄Creating a General Procedure►
◄Tutorial: Writing Event-Driven Programs►