我有许多数组,其中包含不同的字符串,例如
array1() = Array("one","two","three")
array2() = Array("siz","help")
我将字符串组合成字符串数组的数组
bigArray() = Array(array1(),array2(),...)
For k = 0 To # in bigArray
reason = causes(xValue, bigArray(k))
Next
但是,当我尝试将 bigArray(k) 传递给函数时,出现错误
Public Function causes(xValue As String, keyWords() As Variant) As String
最佳答案
作业左侧的空括号是多余且令人困惑的,请删除它们。
我猜bigArray
被声明为这样,如果有的话:
Dim bigArray [As Variant]
If it's not declared, specify
Option Explicit
at the top of your module (always do this!), and declare every variable you're using - otherwise you allow VBA to happily compile & run typos, and that inevitably turns into embarrassing, hard-to-find bugs, and possibly duplicate questions on Stack Overflow.
一个
Variant
可以容纳任何东西,包括数组或锯齿状数组(即数组数组)。keywords
参数虽然...Public Function causes(xValue As String, keyWords() As Variant) As String
被声明为一个数组,其中每个元素都是一个变体。虽然变体元素确实可以是一个数组,但是当您将数组作为参数传递时,没有办法说“每个元素都是变体元素的数组”,所以如果你只是包装它,你会更容易在
Variant
(然后断言您正在查看一个数组):Public Function causes(xValue As String, keyWords As Variant) As String
Debug.Assert IsArray(keyWords)
Debug.Assert IsArray(keyWords(LBound(keyWords))
您的
For
循环假设下边界是:For k = 0 To # in bigArray
不做任何假设的循环是:
For k = LBound(bigArray) To UBound(bigArray)
关于arrays - vba从数组数组中提取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51312029/