Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Instantiating variables
Message
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00406736
Message ID:
00406974
Views:
17
>>>>Dim oBizObj As New myClass
>>>
>>> Never use the above, use the code below, there are almost no good reasons to use the above:
>>>
>>>>or
>>>>Dim oBizObj As myClass
>>>>Set oBizObj = New myClass

>>
>>Thanks. Never heard that before, can you explain?
>
>When using the first syntax, VB delays instanciation until the first use of the class. Let me demonstrate it:
>
>If you write:
>
dim x as new class1
>x.prop1 = "value"
>x.prop2 = "value"
>x.method
>
>VB will compile it this way (to instantiate the class on the first use):
>
dim x as class1
>if x is nothing then set x = new class1
>x.prop1 = "value"
>if x is nothing then set x = new class1
>x.prop2 = "value"
>if x is nothing then set x = new class1
>x.method
>
>Calling yourself the New operator (like your second syntax) allows VB not to execute more statements!
George
Previous
Reply
Map
View

Click here to load this message in the networking platform