Visual Basic: CallByName with multiple “Levels”

我怕爱的太早我们不能终老 提交于 2019-12-12 06:48:18

问题


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

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)

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

is not an option.

How can I make the first example above work?


回答1:


CallByName makes one call. You want to make two.

First a call to the getter:

Dim contactAddress As Address
Set contactAddress = CallByName(contact, "Address", CallType.Get)

Then, ..well then there's no reason to CallByName to assign the Street property value:

contactAddress.Street = new_street


来源:https://stackoverflow.com/questions/43809480/visual-basic-callbyname-with-multiple-levels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!