“无效的过程调用"将变量作为参数传递与传递另一个函数的返回值时出错 [英] "Invalid procedure call" error when passing a variable as argument vs. passing the return value of another function
本文介绍了“无效的过程调用"将变量作为参数传递与传递另一个函数的返回值时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个错误:
无效的过程调用或参数:'AddRange'
invalid procedure call or argument: 'AddRange'
将变量传递给 ArrayList.AddRange 时(),但是当我传递函数的返回值时代码工作正常,即
when passing a variable to ArrayList.AddRange(), but the code works fine when I pass the return value of a function instead, i.e.
我的清单:
Dim Foo
Set Foo = CreateObject("System.Collections.ArrayList")
添加由 GetList()
返回的新列表工作正常:
Adding a new list returned by GetList()
works fine:
Call Foo.AddRange(GetList()) ' works fine
Function GetList()
Set GetList = CreateObject("System.Collections.ArrayList")
End Function
但是传递带有变量 (x
) 的新列表会引发错误:
but passing a new list with a variable (x
) raises an error:
Dim x
Set x = CreateObject("System.Collections.ArrayList")
Call Foo.AddRange(x) ' error: invalid procedure call or argument: 'AddRange'
这是怎么回事?
推荐答案
看起来你需要按值传递数组列表.这有效:
Looks like you need to pass the array list by value. This works:
Call Foo.AddRange((x))
括号内的一组导致参数被传递ByVal
而不是ByRef
.
The inner set of parentheses causes the argument to be passed ByVal
instead of ByRef
.
这篇关于“无效的过程调用"将变量作为参数传递与传递另一个函数的返回值时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文