Home VBA error when passing parameters to factor method:
Reply: 0

VBA error when passing parameters to factor method:

user1143 Published in April 25, 2018, 12:18 pm

I'm testing the Object-Oriented features in VBA and I'm stuck in the problem on how creating new Objects with parameters. Since VBA constructor doesn't allow arguments, I'm adapting the static factory method from Java to VBA. Code below:

CNode class:

Option Explicit

Private pValue As Variant
Private pNode As CNode

' "Constructor" for factory method
Public Sub newNode(value As Variant, node As CNode)
    pValue = value
    Set pNode = node
End Sub

' "Print entire LinkedList"
Public Sub printList()
    Dim aux As CNode
    Set aux = pNode

    While (pNode Is Not Nothing)
        Debug.Print aux.pValue
        Set aux = aux.pNode
End Sub

And the Factory module (my equivalent to the "static" keyword):

Option Explicit

Public Function createNode(value As Variant)
    Dim n As CNode
    Set n = New CNode

    n.newNode value, Nothing
    Set createNode = n
End Function

When I do Set root = Factory.createNode(10), for example, I get the error that "Object variable or With block variable not set".

What am I doing wrong?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.475625 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO