PRB: Object Created w/NEW Instantiated When Passed as ArgumentLast reviewed: September 29, 1997Article ID: Q129449 |
The information in this article applies to:
SYMPTOMSVisual 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).
RESOLUTIONWhen 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 instantiatedThis 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.
STATUSThis behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
Keywords : APrg APrgOther VB4ALL VB4WIN vbwin Technology : kbvba Version : WINDOWS:3.0 4.0 Platform : WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |