J
joeu2004
How can I test if two object variables reference the same object?
For example, suppose I construct a circular linked list of objects.
Then I want to walk the list until I get to the last object --
actually, until I wrap around to the first object again.
I might declare the following class module myTest1:
Private objInst As Long
Public nextObj As myTest1
Private Sub Class_Initialize()
objCnt = objCnt + 1
objInst = objCnt
End Sub
Property Get instNum() 'read-only
instNum = objInst
End Property
I would like to write the following in a standard module:
Public objcnt As Long
Private Sub testit()
Dim first As myTest1, last As myTest1
Dim i As Long, s As String, p As myTest1
'***** build circular linked list
Set first = New myTest1
Set last = first
Set first.nextObj = first
For i = 2 To 10
Set last.nextObj = New myTest1
Set last = last.nextObj
Set last.nextObj = first
Next
'***** walk circular list
s = first.instNum
Set p = first.nextObj
Do Until p = first '<--- does not work
s = s & Chr(10) & p.instNum
Set p = p.nextObj
Loop
MsgBox s
End Sub
Work-around: I must write `Do Until p.instNum = first.instNum`. I
would like to avoid this.
For example, suppose I construct a circular linked list of objects.
Then I want to walk the list until I get to the last object --
actually, until I wrap around to the first object again.
I might declare the following class module myTest1:
Private objInst As Long
Public nextObj As myTest1
Private Sub Class_Initialize()
objCnt = objCnt + 1
objInst = objCnt
End Sub
Property Get instNum() 'read-only
instNum = objInst
End Property
I would like to write the following in a standard module:
Public objcnt As Long
Private Sub testit()
Dim first As myTest1, last As myTest1
Dim i As Long, s As String, p As myTest1
'***** build circular linked list
Set first = New myTest1
Set last = first
Set first.nextObj = first
For i = 2 To 10
Set last.nextObj = New myTest1
Set last = last.nextObj
Set last.nextObj = first
Next
'***** walk circular list
s = first.instNum
Set p = first.nextObj
Do Until p = first '<--- does not work
s = s & Chr(10) & p.instNum
Set p = p.nextObj
Loop
MsgBox s
End Sub
Work-around: I must write `Do Until p.instNum = first.instNum`. I
would like to avoid this.