我有一个类 - “Class1”的属性 - “attribute1”作为字符串。 该属性的可能vlaues是{1,2}VBA自定义类,通过属性值获取所有对象
Class 1模块
Private pattribute1 As String
Public Property Get attribute1() As String
attribute1 = pattribute1
End Property
Public Property Let attribute1 (Value As String)
pattribute1 = Value
End Property
以我主程序,我需要与等于ATTRIBUTE1值检索所有的对象{1}。
主模块
Dim col As New Collection
'Create objects
Do While j <= 5
Dim obj As Class1
Set obj= New Class1
if j<3 then
obj.attribute1 = "1"
else
obj.attribute1 = "2"
end if
j = j + 1
Loop
Set col = 'get all objects from Class1 with attribute equal to "1"
这是最有效的方式做到这一点?
谢谢您提前。
请分享你当前的代码,我们会很乐意帮助 –
如果你的属性的可能的值是1,2,3,岂不是更好地使用int或枚举。 – basslo