LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem Using an Object Variable in a Class Definition

Hello,

I was hoping to get some help with what I hope is a simple problem. I
am trying to nest a user defined object inside another user defined
object. The syntax seems to work but it does not achieve the desired
result. It works using Type statement in traditonal non object mode
but when I convert it to objects, it fails.

Here is the code using the traditional approach. I used a street
intersection as an example.
-------------------------------------------------------------------------
'Commented code included to show full implementation
Type Signal
Red As Boolean
'Yellow As Boolean
'Green As Boolean
End Type

Type Intersection
North As Signal
'South As Signal
'East As Signal
'West As Signal
End Type

' Here is the invocation that shows the state of one light at the
intersection

Sub TraditionalVersion()
Dim HollywoodAndVine As Intersection
MsgBox HollywoodAndVine.North.Red 'DESIRED RESULT
End Sub
---------------------------------------------------------------------------
Notice I can declare a type as another type and then access the
variables using standard .dot notation

I want to convert these variables to objects and achieve the same
result. Here is the code I tried (The two classes are on separate
class modules)

--------------------------------------------------------------------------------
' Intersection Class
'Properties for commented code omitted
Private b_north As Object
'Private b_south As Object
'Private b_east As Object
'Private b_west As Object

Public Property Get NorthBound() As Object
NorthBound = b_north
End Property

Public Property Let NorthBound(TransDirection As Object)
b_north = TransDirection
End Property
------------------------------------------------------------------------------

'Signal Class
'Properties for commented code omitted
Private b_red As Boolean
'Private b_yellow As Boolean
'Private b_green As Boolean

Public Property Get RedLight() As Boolean
RedLight = b_red
End Property

Public Property Let RedLight(TransRed As Boolean)
b_red = TransRed
End Property
-------------------------------------------------------------------

'Main Control Loop
Sub ObjectVersion()
Dim ParkAveAndFifth As New IntersectionObject
Dim NorthSignal As New SignalObject
MsgBox NorthSignal.RedLight 'This statement proves that the
NorthSignal Object gets created
Set ParkAveAndFifth.NorthBound = NorthSignal 'Assign local object
variable to object variable in the Intersection Object
'Previous line of code Generates Object Variable Not Set error
message. Why???
MsgBox ParkAveAndFifth.NorthBound.RedLight 'DESIRED RESULT
End Sub

It seems like this should work. Sorry for the long post but I'm sure
I'm just making a dumb mistake. Thank you in advance. I really
appreciate your help.

Box



------------------------------------------------
Message posted from http://www.ExcelTip.com/

-- View and post Excel related usenet messages directly from http://www.ExcelTip.com/forum
-- Hundreds of free MS Excel tips, tricks and solutions at http://www.ExcelTip.com/
------------------------------------------------
 
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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
VBA variable definition help needed. jenn k New Users to Excel 4 September 5th 08 08:55 PM
Solver Problem Definition testspecmed Excel Worksheet Functions 0 October 5th 06 07:06 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Object class in Excel VBA Tom Chau Excel Discussion (Misc queries) 1 June 29th 06 11:29 AM


All times are GMT +1. The time now is 10:37 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"