B
Boxman
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
------------------------------------------------
-- View and post Excel related usenet messages directly from http://www.ExcelTip.com/forum
at http://www.ExcelTip.com/
------------------------------------------------
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
------------------------------------------------
-- View and post Excel related usenet messages directly from http://www.ExcelTip.com/forum
at http://www.ExcelTip.com/
------------------------------------------------