Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6

Status
Not open for further replies.

willrae

Programmer
Sep 13, 2002
22
GB
Anyone know the difference between CreateObject and using New to create an object?
 
Understanding the answer to this question means understanding the difference between early binding and late binding. When you use the "New" keyword, you are telling VB exactly what kind of object you are going to use in your program such as:

dim objRS as New Recordset

Visual Basic now knows that objRS is a recordset and thus can include the proper object linking when the program is compiled. This is called early binding and is a bit faster at run time. It also allows the compiler to catch syntax errors when using the object's methods and properties.

However,

dim objRS as object
set objRS = CreateObject("ADODB.Recordset")

.. is late binding. When compiling, VB doesn't know what objRS is, that is resolved at run time.

In practice, only use late binding when necessary.
 
Thank you for the help Adam. An object created with New must be referenced. And this is early binding. Using a general object is late binding. OK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top