Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
I construct several classes and store them sequentually in a collection
as they are created. Each class is unique. To access a method of the class I need to cast back to the original class type. How can I determine the class type during runtime? See the following pseudo code. Dim myCollection as New Collection Dim myClass1 as Class1 Dim myClass2 as Class2 Set myClass1 = new Class1 myCollection.Add Item:=myClass1 Set myClass2 = new Class2 myCollection.Add Item:=myClass2 set myClass1 = new Class1 myCollection.Add Item:=myClass1 Later Dim nowClass1 as Class1 Dim nowClass2 as Class2 Set nowClass1 = myCollection.Item(1) ' Same class Set nowClass2 = myCollection.Item(1) ' Not the same class *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
Edward Ulle wrote :
I construct several classes and store them sequentually in a collection as they are created. Each class is unique. To access a method of the class I need to cast back to the original class type. How can I determine the class type during runtime? See the following pseudo code. Edward do you mean this? Select case TypeName(myCollection(1)) case "Class1" Set nowClass1 = myCollection(1) case "Class2" Set nowClass2 = myCollection(1) End Select -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
Yes thank you. I did not look at TypeName because I thought it only applied to user defined types not classes. Thanks again. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
Edward Ulle wrote ...
I construct several classes and store them sequentually in a collection as they are created. Multiple class types in the same collection? This is a stab in the dark but you may be interested in VBA's version polymorphism. See: http://msdn.microsoft.com/library/de...ismallthat.asp Jamie. -- |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
Edward Ulle wrote ...
Set myClass1 = new Class1 myCollection.Add Item:=myClass1 Set myClass2 = new Class2 myCollection.Add Item:=myClass2 Another thought: a Collection object has no functionality to retrieve the key that was used to add an item. You may prefer to use an 'container' object that does e.g. a Dictionary object (I use a fabricated ADO recordset myself, of course <g). Jamie. -- |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
Jamie Collins wrote :
... I use a fabricated ADO recordset myself, of course <g). Jamie. -- shaped where possible :) -- keepITcool | www.XLsupport.com | keepITcool chello nl | amsterdam |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Determine the class of an object
"keepITcool" wrote ...
... I use a fabricated ADO recordset myself, of course <g). shaped where possible :) Actually, my object models are hierarchical, not my collection classes <g. Jamie. -- |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Object class in Excel VBA | Excel Discussion (Misc queries) | |||
How I can determine a base class of a procedure's incoming parameter? | Excel Programming | |||
Class and object persistence | Excel Programming | |||
Problem Using an Object Variable in a Class Definition | Excel Programming |