在VBA中创建2d数组列表 [英] creating 2d array lists in VBA
本文介绍了在VBA中创建2d数组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在VBA中创建2d数组列表的练习.我相信我遇到语法问题.我在将y轴项添加到行时遇到问题.我收到一个错误:multiList.Add(List)出现无效的过程或参数".
I am trying to practice with creating 2d array lists in VBA. I believe I am having a syntax issue. I am having trouble adding the y axis items into the rows. I get an error:'Invalid Procedure or argument" for multiList.Add(List).
我首先初始化x轴以创建数组列表行,然后使用Combined.count初始化列.
I first initialise the x axis to create the array list rows, then I initalise the columns with combined.count.
Sub Test()
Dim xaxis As Integer
xaxis = 4
Dim combined As New ArrayList
combined.Add ("version1")
combined.Add ("version2")
combined.Add ("version3")
combined.Add ("version4")
combined.Add ("version5")
combined.Add ("version6")
combined.Add ("version7")
Dim multiList As ArrayList
Set multiList = New ArrayList
'initialise empty array list of size xaxis with lists inside
For r = 0 To xaxis
Dim List As ArrayList
Set List = New ArrayList
multiList(r).Add (List)
Next
'fill the array lists
For x = 0 To xaxis
For y = 0 To combined.Count
multiList(x).Add (combined(y))
Next y
Next x
'print the array list
For x = 0 To xaxis
For y = 0 To combined.Count
Debug.Print (multiList(x)(y))
Next y
Next x
End Sub
这样做的总体目的是进行一些交叉引用,并根据x轴项是否包含组合"项来填充2d数组列表.
The overall purpose of this is to do some cross referencing and fill the 2d array list based on whether the x axis items contains or doesnt contain items from 'combined'
推荐答案
希望这是您需要的:
Sub Test()
Dim xaxis As Integer
xaxis = 4
'First Arraylist Contains 7 strings
Dim combined As New ArrayList
For i = 1 To 7
combined.Add ("version" & i)
Next i
'Second TotalArraylist contains 4 child Arraylists 1 to 4
Dim multiList As New ArrayList
Dim mul_element As ArrayList
For r = 1 To xaxis
Set mul_element = New ArrayList
multiList.Add mul_element
Next
'fill the TotalArraylist lists
For Each mul_element In multiList '[4 child Arraylists]
For y = 0 To combined.Count - 1 '[7 strings] 0 to 6
mul_element.Add (combined(y))
Next y
Next mul_element
'print the string stores in mul_element(Child arraylist) in multiList(Total arraylist)
For x = 0 To multiList.Count - 1 '[4 element] 0 to 3
For y = 0 To combined.Count - 1 '[7 element] 0 to 6
Debug.Print multiList(x)(y)
Next y
Next x
End Sub
这篇关于在VBA中创建2d数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文