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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateObject vs New 1

Status
Not open for further replies.

willrae

Programmer
Sep 13, 2002
22
GB
VB6

Anyone know the difference between CreateObject and using New to create an object?
 
One difference.
New must have reference, CreateObject does not e.g.
Dim objFSEarly as Scripting.FileSystemObject ' Early binding, need reference
Dim objFSLate as object ' Late binding. No ref

Set objFSEarly = New Scripting.FileSystemObject
Set objFSLate = CreateObject("Scripting.Dictionary") Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
As well as being faster in execution, early binding (Set myObject = New SomeClass) also lets Intellisense know what you're using, so you get the list of accessible methods when you press "." When you can use "= New" then as a general rule do so.

In VBScript you don't have the option of early binding because the only datatype is Variant, so CreateObject() is the only way to instantiate an object. Also, if you're developing for MTS (and probably COM+, I'm a bit out-of-date OS-wise!) you'll need a lot more CreateObject (and other stuff but that's a different story...)

Mike
 
Thanks Mike, I'm even more aware of the penalties involved in Late Binding now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top