Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object class in Excel VBA Tom Chau Excel Discussion (Misc queries) 1 June 29th 06 11:29 AM
How I can determine a base class of a procedure's incoming parameter? Dmitry V. Petkun Excel Programming 1 November 12th 03 01:41 PM
Class and object persistence James Neumann[_2_] Excel Programming 0 September 9th 03 03:48 PM
Problem Using an Object Variable in a Class Definition Boxman Excel Programming 2 August 28th 03 03:05 AM


All times are GMT +1. The time now is 02:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"