问题
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