Class Excel VBA:如何将项添加到类内的集合中?
我有一个包含自身集合的类。(顶级类包含集合中详细实例的摘要版本。) 目前集合是一个公共变量,因为我还没有弄清楚使用私有变量的所有细节。我可以稍后再解决 如何将项目添加到集合中?由于缺少对象变量,我收到错误91。 谢谢你之前的帮助。我一直在对代码进行重新配置,以便更广泛地使用类,事情的进展非常顺利 类cPEClass Excel VBA:如何将项添加到类内的集合中?,class,excel,vba,Class,Excel,Vba,我有一个包含自身集合的类。(顶级类包含集合中详细实例的摘要版本。) 目前集合是一个公共变量,因为我还没有弄清楚使用私有变量的所有细节。我可以稍后再解决 如何将项目添加到集合中?由于缺少对象变量,我收到错误91。 谢谢你之前的帮助。我一直在对代码进行重新配置,以便更广泛地使用类,事情的进展非常顺利 类cPE Public PE_Details As Collection ' collection of cPE Public PE_ID as integer Public PE_ID_Index a
Public PE_Details As Collection ' collection of cPE
Public PE_ID as integer
Public PE_ID_Index as integer
' Add to the detailed list of PE's
Public Function AddPEDetail(ByRef cPE_Detail As cPE)
PE_Details.Add cPE_Detail ' ERROR: Object variable or With
' block variable not set
End Function
调用此函数的模块代码如下所示:
Dim clsPE As cPE ' Summary version of PE
Dim clsPE_Detail As cPE ' A detailed PE
Dim i as Integer
Set clsPE = New cPE ' This is the PE which will also contain a list of detailed PEs
' Add three instances of detailed cPE to the summary cPE object
for i = 1 to 3
Set clsPE_Detail = New cPE
clsPE_Detail.PE_ID = clsPE.PE_ID
clsPE_Detail.PE_ID_Index = clsPE.PE_ID_Index
'etc.
clsPE.AddPEDetail clsPE_Detail ' see above
next i
在cPE类中,添加方法类\u Initialize并初始化变量。现在,您从未设置PE_详细信息,因此它为空/无
Private Sub Class_Initialize()
set PE_Details = New Collection
End Sub
您在哪里设置PE_详细信息?