Question

I have created a class called Class1, and in another module, I want to use the class like this:

Dim budgeunit As Class1

Sub Creattree()
    Dim lvl1p, lvl1m, lvl1dm As Class1

    Set lvl1p = New Class1
    lvl1p.setName ("pear")
    Set lvl1m = New Class1
    lvl1m.setName ("Mango")

    Set budgeunit = New Class1

    budgeunit.addtochildren (lvl1p), budgeunit.addtochildren(lvl1m)
End Sub

But when I compile it, it highlight the budgeunit.addtochildren(lvl1m) and said Byref argument mismatch. I have declare all arguments, I do not know why this happens. The class code:

Dim Children() As Class1
Dim Parent() As Class1
Public level As Integer
Public name As String
Function setName(nm As String)
    name = nm
End Function

Function addtochildren(node As Class1)
    num = Children.Count
    ReDim Children(num + 1) As String
    Children(num) = node
    node.addParent (Me)
End Function
Was it helpful?

Solution

Stefan's answer is correct, but there are other problems as well.

What's this supposed to mean?

budgeunit.addtochildren (lvl1p), budgeunit.addtochildren(lvl1m)

You can't separate two statements with a comma like that. Do you mean this?

budgeunit.addtochildren lvl1p
budgeunit.addtochildren lvl1m

Also you should revise your use of Functions, and probably replace them with Subs. You're not expecting any output from them, so...

Another thing is your use of parentheses. Arguments to subs (and functions with no return value expected) should not be surrounded by parentheses; in some cases having parentheses will make things go wrong. (With some qualification if you use the Call notation, which you do not.)

OTHER TIPS

Your declaration of the variables does probably something different than you expect. Try:

Sub Creattree() 
    Dim lvl1p as Class1, lvl1m as Class1, lvl1dm As Class1

In your declaration, you create two variables of type Variant, and of type Class1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top