SOLVED

VBA: Compiler error: Method or Data member not found

Copper Contributor

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?

2 Replies
best response confirmed by FergO18 (Copper Contributor)
Solution
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.

@FergO18 

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.

1 best response

Accepted Solutions
best response confirmed by FergO18 (Copper Contributor)
Solution
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.

View solution in original post