BUG: Invalid outside Sub Error When Copy or Paste to General (79240)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 2.0
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 2.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
- Microsoft Visual Basic Standard Edition for Windows 1.0
This article was previously published under Q79240 SYMPTOMS
An "Invalid outside Sub or Function" error occurs in the VB.EXE
environment under the following conditions:
- A Sub or Function is copied to the general Declarations section of
a form.
- The name of the Sub or Function copied to the general Declarations
section is changed, or the original Sub or Function that was copied
is deleted.
- The program is run from the VB.EXE environment.
CAUSE
The problem occurs when you copy a subprogram to the general
Declarations section with Sub subname() and End Sub (or Function
functionname () ... End Function) included. If you change the name of
the original or copied Sub (or Function), the error "Invalid outside
Sub or Function" will occur at run time. After the error occurs, the
Sub or Function header of the copied Sub will be missing.
This problem occurs because the Sub or Function that was changed is
treated as the entry of a new procedure. The body of the Sub or
Function and the End Sub (or End Function) statement are treated as an
existing part of the general Declarations section and are left behind.
The behavior is identical when the Sub (or Function) that was copied
is deleted. The Sub (or Function) heading of the copy, residing in the
general Declarations section, is treated as a new Sub or Function
entry.
WORKAROUND
Follow these steps to work around the problem:
- Select (highlight) the remaining code fragment in the general
Declarations section.
- From the Edit menu, choose Cut (ALT, E, T).
- From the Procedure box, choose Test2.
- From the Edit menu, choose Paste to paste the code cut in step 2
above into the body of the Test2 subprogram.
- Delete the duplicate End Sub statement.
Use the following steps to copy a subprogram and avoid the problem:
- Create a new subprogram (such as Sub Test1).
- Create a second subprogram with a different name (such as Sub Test2).
- Copy just the body of the code from the first subprogram (Test1)
into the second subprogram (Test2).
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. We are researching this problem and will
post new information here in the Microsoft Knowledge Base as it becomes
available.
Modification Type: | Major | Last Reviewed: | 12/12/2003 |
---|
Keywords: | kbbug KB79240 |
---|
|