[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Creation of an object

Posted on 2006-04-17
Medium Priority
Last Modified: 2010-04-07
Hi Experts, Could you please let me know the difference between the below 2 declarations.

dim x as object
set x = new object

and dim x as new object


Question by:nmretd
  • 2
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 180 total points
ID: 16468320
Hi nmretd,

In the first case, the object represented by x is not created until the Set statement executes.  In the second, the
object is implicitly created right away.

The first construction is preferable, because it provides greater control over when your object is created.



Author Comment

ID: 16468516
Thanks Patrick. Wondering why there are 2 ways though.. what are the advs and disadvs if any. Please guide. Example would be appreciable.


Accepted Solution

dancebert earned 195 total points
ID: 16468743
If you:

dim x as object
set x = new object

Then later: set x = nothing

Then still later refer to x in your code, x will equal nothing.  However if you:

dim x as new object

Then later: set x = nothing

Then still later refer to x in your code, a new instance of x will be created.  That is usually a bad thing.

Author Comment

ID: 16469251
Great guys. I am cleared.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question