Raymond
Raymond

Reputation: 65

Getting error when calling custom property

I am looking to do a depth first searching algo using vba so i have defined an object called "node" which should contains a "parentNode".

I have tried to define parentNode as collection and use the following

Public Property Let Parent(ByRef inputNode As Node)
    Set parentNode = New Collection
    hasParentNode = True
    parentNode.Add inputNode

End Property

Public Property Get Parent() As Node
    Parent = parentNode.Item(1)
End Property

But when i call node.Parent i got Object variable or With block variable not set

i know that is due to the line "Parent = parentNode.Item(1)" what should be the proper way of doing this? I want it to return the parnetNode assigned by Ref

Thanks

Upvotes: 2

Views: 118

Answers (1)

JimmyPena
JimmyPena

Reputation: 8754

Since Node is an object (I assume, I have no idea what class Node actually is), your code is missing the Set keyword:

Public Property Get Parent() As Node
  Set Parent = parentNode.Item(1) 
End Property

Getting Object variable or With block variable not set usually sometimes means a missing Set keyword.

Upvotes: 3

Related Questions