|
-
Apr 19th, 2001, 04:10 AM
#1
Thread Starter
Lively Member
Can anyone tell me what the difference is between these two codes?
Code1
Code:
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Code2
Code:
Dim rs
Set rs = CreateObject(blah) 'not too sure how to use this function
-
Apr 19th, 2001, 04:49 AM
#2
With the first one, you already have a reference in place.
You add in the reference from the properties menu in vb. Setting a reference here, lets you type in the code as in your first example.
The second one is you creating and setting up the reference to the object via code. This is useful as with vbscript for example - when you're using notepad, you don't have a nice project menu to do all this for you.
With the createobject method, as you create the reference, there's no need for the New keyword as it's automatically a new reference of the object.
So -
Project > Properties > microsoft Excel 8.0 object
is just getting microsoft to do the following for you -
set ObjXls = createobject("Excel.Application")
Hope I made some sense there !
Last edited by alex_read; Apr 19th, 2001 at 05:04 AM.
-
Apr 19th, 2001, 04:53 AM
#3
Thread Starter
Lively Member
Ahh, I get it now, thanks alex!
-
Apr 19th, 2001, 06:14 AM
#4
Black Cat
Also, setting a reference (early-binding) is much faster than using CreateObject at runtime(late-binding).
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
-
Apr 19th, 2001, 07:01 AM
#5
Thread Starter
Lively Member
Yeah, I had a feeling that came in to it. Thanks also.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|