Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Setting up Classes

Duuudes:

I have a question about setting up classes. I currently have a situation
that I need to set up a class that contains properties then those properties
need to have properties. For ex:

I've set a class up called Shapes. The Shapes object then has multiple
shapes under it, Shapes.Square, Shapes.Circle, Shapes.Rectangle, etc.

I want to be able to get the color of a certain shape such as:
Shapes.Square.Color

I know how to set up the properties one level deep in a class with the
property let and property get procedures, but don't understand the syntax of
how to give a property it's own properties, if that makes sense. Do I need to
set up classes for each shape then associate that back to the Shapes object
somehow?

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Setting up Classes

Try something like the following:

'[Class CCircle]
Public Radius As Double

Public Function Area() As Double
Area = 3.1415 * (Radius ^ 2)
End Function

'[Class CSquare]
Public SideLength As Double

Public Function Area() As Double
Area = SideLength ^ 2
End Function

'[Class CShape]
Public Function CircleObj() As Ccircle
Set CircleObj = New Ccircle
End Function

Public Function SquareObj() As CSquare
Set SquareObj = New CSquare
End Function

'[Module1]
Sub AAA()
Dim SH As CShape
Dim SQ As CSquare
Dim SC As Ccircle

Set SH = New CShape
Set SQ = SH.SquareObj
SQ.SideLength = 10
Debug.Print SQ.Area
End Sub

Depending on how complicated you want to go, you could also write your
CCircle and CSquare classes to Implement the CShape interface, which would
allow something like

Dim SH As CShape
Set SH = New CSquare


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"DeathSurfer" wrote in message
...
Duuudes:

I have a question about setting up classes. I currently have a situation
that I need to set up a class that contains properties then those
properties
need to have properties. For ex:

I've set a class up called Shapes. The Shapes object then has multiple
shapes under it, Shapes.Square, Shapes.Circle, Shapes.Rectangle, etc.

I want to be able to get the color of a certain shape such as:
Shapes.Square.Color

I know how to set up the properties one level deep in a class with the
property let and property get procedures, but don't understand the syntax
of
how to give a property it's own properties, if that makes sense. Do I need
to
set up classes for each shape then associate that back to the Shapes
object
somehow?

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Setting up Classes

Preciate it dude.

"Chip Pearson" wrote:

Try something like the following:

'[Class CCircle]
Public Radius As Double

Public Function Area() As Double
Area = 3.1415 * (Radius ^ 2)
End Function

'[Class CSquare]
Public SideLength As Double

Public Function Area() As Double
Area = SideLength ^ 2
End Function

'[Class CShape]
Public Function CircleObj() As Ccircle
Set CircleObj = New Ccircle
End Function

Public Function SquareObj() As CSquare
Set SquareObj = New CSquare
End Function

'[Module1]
Sub AAA()
Dim SH As CShape
Dim SQ As CSquare
Dim SC As Ccircle

Set SH = New CShape
Set SQ = SH.SquareObj
SQ.SideLength = 10
Debug.Print SQ.Area
End Sub

Depending on how complicated you want to go, you could also write your
CCircle and CSquare classes to Implement the CShape interface, which would
allow something like

Dim SH As CShape
Set SH = New CSquare


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


"DeathSurfer" wrote in message
...
Duuudes:

I have a question about setting up classes. I currently have a situation
that I need to set up a class that contains properties then those
properties
need to have properties. For ex:

I've set a class up called Shapes. The Shapes object then has multiple
shapes under it, Shapes.Square, Shapes.Circle, Shapes.Rectangle, etc.

I want to be able to get the color of a certain shape such as:
Shapes.Square.Color

I know how to set up the properties one level deep in a class with the
property let and property get procedures, but don't understand the syntax
of
how to give a property it's own properties, if that makes sense. Do I need
to
set up classes for each shape then associate that back to the Shapes
object
somehow?

Thanks.


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
Calling Classes from Classes J Streger Excel Programming 2 March 23rd 07 01:13 PM
Constructors for Classes Gary F Excel Programming 3 September 8th 06 05:56 PM
Classes containing Classes Adam[_15_] Excel Programming 2 April 1st 06 07:47 AM
Using Classes in .xla oli Excel Programming 2 June 3rd 05 11:37 AM
object classes mark Excel Programming 10 July 1st 04 03:42 PM


All times are GMT +1. The time now is 02:24 AM.

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"