qck.hlp (Table of Contents; Topic list)
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 a General Procedure
                                                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 Creating a General Procedure
 
 ■ A general procedure tells the application how to perform a specific task.
   Once the procedure is defined, it must be explicitly invoked by the
   application.
 
 ■ By contrast, an event procedure remains idle until called upon to respond
   to events caused by the user or triggered by the system.
   See: Creating an Event Procedure
 
 ■ You can place a general procedure in a form module or a code module.
   Use general procedures to divide complex application code into more
   manageable units.
 
 ■ 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 create a general procedure:
 
   1. Open the form or code module where you want to write the procedure
 
   2. From the Edit menu, choose New Sub or New Function
      Select Sub to create a SUB procedure or Function to create a FUNCTION
      procedure. Note that a FUNCTION procedure returns a value and a SUB
      procedure does not.
 
   3. In the text box, type a name for the procedure
 
   4. Choose Edit in Active or Edit in New
      Visual Basic sets up a template so you can enter or edit code for the
      general procedure.
 
 ■ You can also create a new procedure in a code window by typing either
   'SUB procedurename' or' FUNCTION procedurename' and pressing Enter.
 
 ■ Use this syntax to write a SUB procedure:
 
         SUB procedurename (parameters)
              local variable and constant declarations
              statements
         END SUB
 
 ■ Use this syntax to write a FUNCTION procedure:
 
         FUNCTION procedurename (parameters)
              local variable and constant declarations
              statements
         END FUNCTION
 
 ■ General procedures can be used for:
   • Sharing code among controls on one form. Write a general procedure in
     form code and attach an event procedure to each control that calls the
     general procedure.
   • Sharing code among multiple forms. Create a code module and write the
     shared code there as a general procedure. For each form or control you
     want to share the code, attach an event procedure that calls the general
     procedure.
   • Memory management. If you have too much code in a module, you may exceed
     memory limits. Create one or more modules and offload the code by
     attaching short event procedures to the form or its controls that call
     general procedures in other module(s).