Forum Discussion
FergO18
Feb 22, 2022Copper Contributor
VBA: Compiler error: Method or Data member not found
I am trying to implement a doubly linked list. I have two class modules, one for each node and one for the linked list.
Node:
Option Explicit
Private Value As Long
Private prevNode As Node
Private nextNode As Node
Linked List:
Option Explicit
Private head As Node
Public Sub Add(inputValue As Long)
Dim newNode As Node
Set newNode = New Node
newNode.Value = inputValue
Set newNode.nextNode = head
Set head = newNode
End Sub
I am then trying to test the code by making a test module which just adds some nodes:
Option Explicit
Sub Test()
Dim linkedList As New linkedList
linkedList.Add (1)
linkedList.Add (2)
linkedList.Add (3)
linkedList.Add (4)
End Sub
It is saying the that "newNode.Value = inputValue" line throws the error. Why is this happening as the Value attribute is in the Node class?
- I have found my own mistake. I had set the attributes of the nodes to be private, meaning that the test module couldn't access them. Changing those to be public from private has fixed my issue.
2 Replies
You declared the three properties if Node as Private, so they are not visible to other modules.
Either declare them as Public, or create Get/Let/Set methods for them.
- FergO18Copper ContributorI have found my own mistake. I had set the attributes of the nodes to be private, meaning that the test module couldn't access them. Changing those to be public from private has fixed my issue.