Forum Discussion
The above code is working fine for single dimensional array.
My problem here is for 2 dimensional array. I have subscript out of range error at my ReDim Preserve below
Dim arrTestArraỵ()
Set aData = DDT.CSVDriver(strFullFileName)
Call aData.First
intSize = 0
Do While Not aData.EOF()
For i = 0 to aData.ColumnCount - 1
ReDim Preserve arrTestArraỵ(intSize, aData.ColumnCount - 1) -> it is error right at this line: subscript out of range
arrTestArraỵ(intSize,i) = aqConvert.VarToStr(aData.Value(i))
Next
intSize = intSize + 1
aData.Next
Loop
The Preserve keyword can't be used if you change the size of any but the last dimension. See ReDim Statement
Since the number of columns is fixed, make that the unchanging dimension. Transpose the matrix and enter a new row's worth of data down one column of the array. For each new row of data make the array one column wider and enter the next row of date down the next column.
Something like this:
Sub Test Dim RowCount : RowCount = 3 Dim ColumnCount Dim arr, row, column ColumnCount = 5 ReDim arr(ColumnCount - 1, 0) row = 0 Do While row < RowCount ReDim Preserve arr(ColumnCount - 1, row) For column = 0 to ColumnCount - 1 arr(column, row) = row * 10 + column ' new data Next row = row + 1 Loop For row = 0 to RowCount - 1 For column = 0 to ColumnCount - 1 Log.Message("arr(" & row & ", " & column & ") = " & arr(column, row)) Next Next End Sub
Related Content
- 13 years ago
- 3 years ago
Recent Discussions
- 4 days ago
- 4 days ago
- 7 days ago