PRB: Object Created w/NEW Instantiated When Passed as Argument (129449)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q129449 SYMPTOMS
Visual Basic version 4.0 instantiates objects created with the "New"
keyword in cases where Visual Basic version 3.0 does not.
This may apply to earlier versions of VBA (specifically 1.0) used in
Microsoft Excel 5.0 (16-bit).
RESOLUTION
When passing an object (declared with the New keyword) to a procedure,
Visual Basic 4.0 first instantiates the object (if it isn't already
instantiated).
This behavior is different than Visual Basic version 3.0. In Visual Basic
3.0, the object isn't instantiated until a member of the object is
referenced inside the called procedure. If the object is never referenced,
then it is never instantiated. Because a form is not shown when it is
instantiated anyway (it is only shown when the Show method is called), the
only difference in behavior is that the Form_Load event runs at a different
time in Visual Basic 4.0 than in Visual Basic 3.0.
In a TypeOf statement, if an object variable that was declared with the New
keyword is being tested, then Visual Basic 4.0 will instantiate the object
before doing the test. For example:
Dim X As New Form1
If TypeOf X Is Form1 Then ... ' X WILL be instantiated
This is different from Visual Basic 3.0. Visual Basic 3.0 does not
instantiate the object in this case. Visual Basic 3.0 can do this because
it can determine the type of the object even if the object has not yet been
instantiated.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 12/9/2003 |
---|
Keywords: | kbprb KB129449 |
---|
|