vba - 设置作为自定义对象的属性时,对象不支持此属性或方法
问题描述
我有两个自定义类。一个是另一个的财产。我正在尝试从类外部的 Access 表单中设置属性的值。
我在这里不知所措。我试图删除 set 关键字,结果是它执行了 Let 但未定义该值。如果我尝试将其设置为 Nothing,它也会失败。(我知道狗并不是动物的真正属性,这只是为了说明。)
'Animal class
Private dog As Dog
Public Property Get oDog() As Dog
Set oDog = dog
End Property '<<<Error happens here.
Public Property Let oDog(myDog As Dog)
Set dog = value
End Property
'If I don't do this, I get an object variable or with block variable not set error.
Public Sub Class_Initialize()
Set dog = New Dog
End Sub
'Dog class
'Dog properties and methods here.
'Form
Private oAnimal As Animal
Set oAnimal = New Animal
Set oAnimal.oDog = New Dog '<<< that fails
我的最终目标是将自定义类的对象属性设置为新对象,但来自类外部,来自表单。底线是,由于某种原因,当我调用 Set 时,调用的是 getter 而不是“字母”。我知道我做错了什么,我只是不知道它是什么。我敢肯定它是显而易见的。
解决方案
在让您使用“myDog”然后将狗设置为值尝试将其更改为:
Public Property Let oDog(Value As Dog)
Set dog = Value
End Property
推荐阅读
- python - 使用 Python 从 Jira 中提取所有问题时,有没有办法将最新的活动历史记录添加到问题列表中?
- angular - if() 返回的单元测试;在一个函数中
- vb.net - 在没有 Office 365 的计算机上安装 Office 365 组件
- linux - 如何为需要以特定顺序运行的 2 个或更多服务器构建启动/关闭脚本?
- ros - 在动力学上安装turtlebot
- r - 如何使用 Shiny 向 mongodb 提交多种数据类型(数组、字符串等)?
- mqtt - MQTT Sparkplug中的Bdseq和Seq号有什么区别
- python - Pandas groupby 语句查找范围有问题
- node.js - 在 AWS Lambda Node 应用程序中运行 GraphicsMagick 不会产生任何输出
- typescript - 在多次出现时使用相同的类型