BlakeMcKenna
asked on
Storing a 2-dimensional array within a 1-dimensional array
All I'm trying to do here is store a collection within a collection...the collection being arrays. My problem is the syntax. I have built the 2-dimensional array, now I wish to add it to the 1-dimensional array but not sure how to do it. Here is my code below.
Dim idx As Integer = 0
Dim arr1() As String
Dim arr2(,) As String
Redim Preserve arr1(idx)
For x As Integer = 0 To 14
Redim Preserve arr2(x, y)
For y As Integer = 0 To 9
Redim Preserve arr2(x, y)
arr2(x, y) = "Test " & x & " and " & y
Next
Next
arr1(idx) = arr2
I'm getting an error where I assign arr2 to arr1. It says "Value of type 2-dimensional array of String cannot be converted to String". I also tried this:
arr1(idx) = arr2()
The above syntax gave me the error "Number of indices is less than the number of dimensions of the indexed array".
Dim idx As Integer = 0
Dim arr1() As String
Dim arr2(,) As String
Redim Preserve arr1(idx)
For x As Integer = 0 To 14
Redim Preserve arr2(x, y)
For y As Integer = 0 To 9
Redim Preserve arr2(x, y)
arr2(x, y) = "Test " & x & " and " & y
Next
Next
arr1(idx) = arr2
I'm getting an error where I assign arr2 to arr1. It says "Value of type 2-dimensional array of String cannot be converted to String". I also tried this:
arr1(idx) = arr2()
The above syntax gave me the error "Number of indices is less than the number of dimensions of the indexed array".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER