且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将属性作为用户窗体控件的参数传递

更新时间:2023-12-06 08:52:22

让我们看一下这里被调用的内容:

Let's look at what's being invoked here:

Obj.objProperty = Obj.objProperty + Increment

忽略您将String本地/参数非法视为Obj成员的事实,您在分配的两边都有Obj.objProperty,因此从句法上讲,我们有:

Ignoring the fact that you're illegally treating a String local/parameter as a member of Obj, you have Obj.objProperty on both sides of the assignment, so syntactically, we have:

[object].[property-let] = [object].[property-get] + [parameter]

换句话说,没有一种方法可以使用单个CallByName调用:您需要首先计算分配的RHS,并且为此,您需要调用Property Get成员来读取当前值,然后添加increment,然后然后调用Property Let成员以 write 新值.

In other words, there's no way that can work with a single CallByName invocation: you need to first compute the RHS of the assignment, and in order to do that you need to invoke the Property Get member to read the current value, then add the increment, and then invoke the Property Let member to write the new value.

Dim currentValue As Double
currentValue = CallByName(obj, objProperty, vbGet)

这就是 read 部分.然后,您可以执行 write 部分:

So that's the read part. Then you can do the write part:

CallByName obj, objProperty, vbLet, currentValue + increment

不确定Prop本地Variant变量将用于什么.

Not sure what the Prop local Variant variable would be used for.