我使用另一个类成员变量维护了类对象的数组。我无法将对象数组设置为类变量。能够调用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
答案 0 :(得分: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