我得到一个错误:
invalid procedure call or argument: 'AddRange'
将变量传递给 ArrayList.AddRange() 时,但是当我改为传递函数的返回值时代码工作正常,即
我的 list :
Dim Foo
Set Foo = CreateObject("System.Collections.ArrayList")
添加由 GetList()
返回的新列表效果很好:
Call Foo.AddRange(GetList()) ' works fine
Function GetList()
Set GetList = CreateObject("System.Collections.ArrayList")
End Function
但是传递带有变量 (x
) 的新列表会引发错误:
Dim x
Set x = CreateObject("System.Collections.ArrayList")
Call Foo.AddRange(x) ' error: invalid procedure call or argument: 'AddRange'
这是怎么回事?
最佳答案
看起来您需要按值传递数组列表。这有效:
Call Foo.AddRange((x))
内部括号组导致参数被传递 ByVal
而不是 ByRef
。
关于.net - 传递变量作为参数与传递另一个函数的返回值时出现 "Invalid procedure call"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747341/