【发布时间】:2020-12-08 14:35:13
【问题描述】:
我想知道是否可以创建我自己的类,它的行为就像一个集合。最好在示例中显示:
我目前的知识:
类模块MyClass
Public oCollection As Collection
Public OtherData as Long
... 'Another Variables, Properties, Functions and Subs
模块
...
For Each oItem In MyClass.oCollection 'I need to address Collection inside the object
If oItem.OtherData = 0 Then
...
我想要达到的目标:
...
For Each oItem In MyClass 'Want to be able to iterate over oCollection just from Class
If oItem.OtherData = 0 Then
...
感谢您的建议。
【问题讨论】:
-
为什么?除了将行减少几个字符并降低可读性(或至少是原始实现的“自我文档”)之外,还有什么好处?
-
看看here。它将准确显示它是如何完成的,但它也会向您显示 x64 上的相关错误
-
@sous2817 你可能是对的。我又想了想,我想要它主要是因为我的课程设计不佳。最初的原因是
MyClassprops 可以返回“修改”MyClass,或者修改oCollection集合。很难(从道具名称)决定返回什么,所以我经常忘记添加.oCollection,它会抛出错误。但是我没有意识到问题是返回了错误的对象,并且倾向于在属性代码中搜索错误。