0

我已经使用另一个类成员变量维护类对象数组。我无法将对象数组设置为类变量。能够调用 setter 方法但给出错误“无法分配数组”

Class module AA

private c as integer
private d as integer

Class module B
private a(50) as AA

public sub setA(byref a1() as AA)
    a = a1        ' this assignment not work.
end sub

public function getA() as AA()
    getA = a              ' this work
end function

Module main

dim tags() as A
dim tag as A
with B
    Redim preserve tags(ubound(.getA()) ' get the class module b array and set the element as 50
    for i =0 to ubound(tags)
        if tags(i) is nothing then
            tag.setC(3)
            tag.setD(5)
            tags(i) = tag
        end if
    next i

    .setA tags ' call the setter method but gives error can't assign a array

end with
4

1 回答 1

0

如果声明数组的大小,则不能分配给数组。尝试这样的事情:

Class module B
private a() as AA

public sub setA(byref a1() as AA)
    a = a1        ' this should work now.
end sub

public function getA() as AA()
    getA = a              ' this work
end function

public sub class_initialize
    redim a(50)
end sub
于 2013-11-13T13:31:18.383 回答