问题描述
我已经为此工作了很多时间,但是我仍然无法继续执行我的代码.
I've been working on this for quite a bit now but I still cannot get my code going.
我有一个名为Contact
的类,该类具有只读属性Address
. Address
类具有类似Street
和City
的属性.现在,我要像这样分配联系人的街道:
I have a class called Contact
which has a read-only property Address
. The Address
class has properties like Street
and City
. Now I want to assign a contact's street like this:
CallByName(contact, "Address.Street", CallType.Set, new_street)
但是我收到一条错误消息,说"Address.Street"不是Contact
的成员.
But I am getting an error saying "Address.Street" is not a member of Contact
.
我需要通过名称来设置属性
I need to set the property via its name so
contact.Adress.Street = new_street
不是一个选择.
如何使上面的第一个示例起作用?
How can I make the first example above work?
推荐答案
CallByName
调用一个.你想做两个.
首先调用吸气剂:
Dim contactAddress As Address
Set contactAddress = CallByName(contact, "Address", CallType.Get)
然后,..那么没有理由让CallByName
分配Street
属性值:
Then, ..well then there's no reason to CallByName
to assign the Street
property value:
contactAddress.Street = new_street
这篇关于Visual Basic:具有多个“级别"的CallByName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!