Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Class within a class

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Class within a class


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Class within a class


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Class within a class

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Class within a class

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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Class within a class

While you cannot have a class nested in another class, there is no
restriction on the use of 'peer' classes.

Create a class module named colDefinition. Create another class named
deductionFile. Now, in deductionFile you can declare a single variable of
type colDefinition or a static array or a dynamic array or insert objects of
type colDefinition in a collection or...

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
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.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Class within a class

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Class within a class

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
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
problems with my class medicenpringles[_17_] Excel Programming 6 October 20th 05 09:37 PM
Class Modules Pavlos Excel Programming 5 January 19th 05 05:31 PM
Class module Chip Pearson Excel Programming 0 January 19th 05 03:01 PM
RaiseEvent from a class contained in a 2nd class collection? Andrew[_16_] Excel Programming 2 January 6th 04 04:22 PM
Is it possible to set a class member to be another class member? Michael[_21_] Excel Programming 3 October 30th 03 08:28 AM


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

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

About Us

"It's about Microsoft Excel"