Microsoft KB Archive/129949

= PRB: Empty Sub Procedures Are Not Persistent =

Article ID: 129949

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q129949



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.</li></ol>

Additional query words: 4.00 vb4win vb4all

Keywords: kbprb KB129949

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.