本文介绍了Visual Basic:具有多个“级别"的CallByName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此工作了很多时间,但是我仍然无法继续执行我的代码.

I've been working on this for quite a bit now but I still cannot get my code going.

我有一个名为Contact的类,该类具有只读属性Address. Address类具有类似StreetCity的属性.现在,我要像这样分配联系人的街道:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:07