General discussion

Locked

To find "Class" for CreateObject method

By nirman123_doshi ·
The syntax of "CreateObject" in VB/ VBA is
"CreateObject(Class As String, [ServerName As String])"
So if i want to use CreateObject method in VB or VBA for creating any control at runtime then I have to pass "Class" parameter. So how can I find a "Class" for a particular object. That is, if I want to find what is to be passed in "Class" parameter, if I want to create a TextBox using CreateObject method, then how can i find what is to be passed. Is there any code available to find.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tony Hopkinson In reply to To find "Class" for Creat ...

Not usually as complicated as that in VB the class name is the type so the class name of a textbox is textbox, label is label etc.

Collapse -

by Gast?n Nusimovich In reply to To find "Class" for Creat ...

When you use CreateObject method to instanciate an object of a certain class (in this case, you are using late binding), you must pass as parameter the COM programmatic identifier, or ProgID for short that is associated to the COM component that contains the class in question.

How do you know what is the ProgID of a given class?

Well, you have a your disposal a few ways to find out this.

The safest way is to use first the early binding way: you use References in your Visual Basic IDE to include a reference to the component that contains the class in question, and then you press F2 (Object Browser) and there you will find the ProgID for your class.

For instance, to create an ADO Connection object with CreateObject, you search with Object Browser Connection and you will find that it says Connection, member of ADODB, so the ProgID is:

ADODB.Connection,

That is:

Dim objConn as Object
Set objConn = CreateObject("ADODB.Connection")

You could also search in the Registry of your PC the ProgID for the class in question, but this is a little for difficult to come by if you are not used to navigate Windows' Registry.

Good Luck!

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums