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

test existence of a source class at run time 1

Status
Not open for further replies.

murrayja

Programmer
May 6, 2000
90
US
I have the need to test for the existence of a source code class module at run time. Based on text in a document I want to instantiate an object of a particular name but don't want to include all source classes in every distribution.

eg

Case "AZC_WRD"
Set obj = New azc_wrd
Case "AZC_CRT"
Set obj = New azc_crt

I would like to be able to ...
Case "AZC_WRD"
Set obj = New azc_wrd
Case "AZC_CRT"
if classexists("azc_crt") then _
Set obj = New azc_crt

Suggestions?

 
See create object.
You are looking for late binding I think.

Also for methods have a lok at callbyname (I think it's called)

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Use "CreateObject" to create the class defining object as just Object
e.g.
say your different object names where in a string var sObjName (in your e.g. this might be AZC_WRD, AZC_CRT etc
Dim objTest as Object
Set objTest = CreateObject(sObjName)

Of course this means app is fully late bound - what you really need is "Interfaces" (look up "Implements" keyword but this is relatively advanced) - so all objects are bound to the interface that is then the same for all various objects - then the individual object still gets made using CreateObject but the var it goes into is declared as having the type of the "Interface" - this allows code completion etc of your object calls when coding and full "at compile" checking of calls etc while still allowing dynamic objects ... I could show you exactly how but there would be a charge ...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top