ByRef 参数与 Excel 中的 VBA 不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10986528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ByRef Argument Mismatch with VBA in Excel
提问by Ehudz
I have a Let property defined as:
我有一个 Let 属性定义为:
Public Property Let Set_ChanArray_Enabled1(i As Integer, j As Integer, choice As Boolean)
ChanArray(i, j).Enabled1 = choice
End Property
In a sub defined in the same object module, I attempt to do the following:
在同一个对象模块中定义的子中,我尝试执行以下操作:
For j = 4 To 44
Me.Set_ChanArray_Enabled1(j, 1) = True
Me.Set_ChanArray_Enabled1(j, 3) = True
Next j
But VBE gives me a ByRef argument mismatch pointing to the j passed into
但是 VBE 给了我一个 ByRef 参数不匹配,指向传入的 j
Me.Set_ChanArray_Enabled1(j, 1) = True
I have defined both j and the parameter passed into the method as integers so I am not sure what is wrong.
我已经将 j 和传递给方法的参数都定义为整数,所以我不确定有什么问题。
回答by Alex K.
That error indicates something is wrong with the typing of j
(i.e its not of type integer).
该错误表明输入有问题j
(即它不是整数类型)。
Have you declared it in a statement like; dim j, i as integer
? If so then only i
is an integer (you need to repeat as integer
).
你有没有在这样的声明中声明它;dim j, i as integer
? 如果是这样,那么只有i
一个整数(你需要重复as integer
)。
(Using byval
appears to "fix" this because its pass-by-copy semantics allow VBA to perform an automatic type conversion to integer before calling Set_ChanArray_Enabled1
).
(使用byval
似乎“修复”了这个问题,因为它的通过复制语义允许 VBA 在调用之前执行到整数的自动类型转换Set_ChanArray_Enabled1
)。