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

VBA error when passing parameters to factor method:

Nelsão
1#
Nelsão Published in 2017-12-07 16:18:30Z

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
    Wend
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.33034 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO