Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have defined a custom class called deductionFile. It has several
properties like fileName,fileDate,etc. It refers to a fixed-width text file that I am importing into excel. The file is comprised of several fields, and each field has information about it like width, typeOfData, Description, etc. What I want to do is have a class called colDefinition that is a member of the deductionFile class. Therefore, each deductionFile object would have multiple colDefinition objects, each with their own properties. I would then refernce it something like this: deductionFile.colDefinition(i).width Basically I want to have the same type of functionality as when you write worksheets(1).range("foo").cells(1,1). Worksheets has a collection of ranges, which has a collection of cells. I want to have a deductionFile object that has a collection of colDefinitions. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello Josh, The class functionality you are describing exists in code written in "C". In my experience, VBA has never had more than 1 level of class exposure (MyClass.Myproperty). It may be possible to do, but I have never seen or read about it being done. If it can, I would love to know how. Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=505533 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() try collections. You can have collections of objects and of collections. regard -- tony ----------------------------------------------------------------------- tony h's Profile: http://www.excelforum.com/member.php...fo&userid=2107 View this thread: http://www.excelforum.com/showthread.php?threadid=50553 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This is fine if all you are using the class for is storing and retrienving
variables, but you aren't able to define your own methods. i.e. myClass.mySubClass.getInfo() "tony h" wrote in message ... try collections. You can have collections of objects and of collections. regards -- tony h ------------------------------------------------------------------------ tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074 View this thread: http://www.excelforum.com/showthread...hreadid=505533 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Create a "column" class and then create instances of it in your main class.
Not really that different from creating any other object within a class. Tim. -- Tim Williams Palo Alto, CA "Josh Rolfe" wrote in message ... This is fine if all you are using the class for is storing and retrienving variables, but you aren't able to define your own methods. i.e. myClass.mySubClass.getInfo() "tony h" wrote in message ... try collections. You can have collections of objects and of collections. regards -- tony h ------------------------------------------------------------------------ tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074 View this thread: http://www.excelforum.com/showthread...hreadid=505533 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Josh,
Out of curiosity I built a small test case of a class within a class, Class1 and Class2. I'm sure there are some limitation but the behaviour in VBA is very much like the Excel Object Model. In particular in the Test module the Add method simply returns a new instance of Class2 and assigns the name. With the Collection in Class1 you could also assign key names to select the particular instance of Class2. Option Explicit Sub Test() Dim oClass1 As Class1 Set oClass1 = New Class1 oClass1.Add.SetName = "first" oClass1.Add.SetName = "second" oClass1.Add.SetName = "third" MsgBox oClass1.GetClass2(2).GetName End Sub Option Explicit ' Class1 Private cClass2 As Collection Private Sub Class_Initialize() Set cClass2 = New Collection End Sub Private Sub Class_Terminate() Dim oClass2 As Class2 For Each oClass2 In cClass2 Set oClass2 = Nothing Next Set cClass2 = Nothing End Sub Public Function Add() As Class2 Dim oTemp As Class2 Set oTemp = New Class2 cClass2.Add oTemp Set Add = oTemp End Function Public Property Get GetClass2(i As Long) As Class2 If i < 1 Or i cClass2.Count Then Set GetClass2 = Nothing Else Set GetClass2 = cClass2(i) End If End Property Option Explicit ' Class2 Private strName As String Public Property Let SetName(strText As String) strName = strText End Property Public Property Get GetName() As String GetName = strName End Property *** Sent via Developersdex http://www.developersdex.com *** |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Josh,
I realized my Class1 Class_Terminate was wrong. In fact it was doing nothing. It should be. Private Sub Class_Terminate() Dim i As Long For i = 1 To cClass2.Count cClass2(i) = Nothing Next Set cClass2 = Nothing End Sub *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
problems with my class | Excel Programming | |||
Class Modules | Excel Programming | |||
Class module | Excel Programming | |||
RaiseEvent from a class contained in a 2nd class collection? | Excel Programming | |||
Is it possible to set a class member to be another class member? | Excel Programming |