The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft
Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
SYMPTOMS
You receive the "Sub or Function not defined" error when executing code
that references an empty event procedure.
CAUSE
If you have an event procedure that is being called from another Sub
procedure in the program, and you delete all the code in the event
procedure, any references to that event procedure generate an error message
at compile time.
RESOLUTION
Remove references to the empty event procedures or place a comment line
into the procedure.
STATUS
This behavior is by design.
MORE INFORMATION
The Visual Basic Help file lists the following possible reasons for
the "Sub or Function not defined" error:
- The specified procedure is not visible to the calling procedure.
Procedures in a form cannot be called from procedures outside the form.
Use Find on the Edit menu to locate the procedure.
- You have declared a dynamic-link library, but the routine is not in the
specified library.
- You have misspelled the name of your procedure.
An additional possible cause for this error is that you have called an
empty event procedure. Empty Sub procedures are not persistent in Visual
Basic, that is, the compiler strips out empty event procedures before the
binding tables are built such that a reference does not exist to the
procedure in the compiled code, and as a result, it is undefined.
Steps to Reproduce Behavior
- Start a new project in Visual Basic. Form1 is created by default.
- Add the following code to the Form1_Click event procedure:
Private Form1_Click()
Command1_Click
End Sub
- Add a command button (Command1) to Form1.
- Run the program. When you click the form, the error is generated.
- Furthermore, if you nondestructively edit the line "Command1_Click"
(that is, retype a portion of the line) the error "Sub or Function not
defined" is generated at compile time.
|