Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub arrays(ByVal ss As DataTable, ByRef rr() As String, ByRef rr1()() As String, ByRef id() As Integer, ByRef attr()() As String)
        Dim cc As DataColumn
        Dim cr As DataRow
        Dim z As Integer
        Dim m As Integer
        Dim j As Integer
        Dim i As Integer
        Dim d As Integer
        Dim k As Integer
        k = 0
        d = 0
        j = 0
        i = 0
        z = 0
        m = 0
        For Each cc In ss.Columns
            ReDim Preserve rr(z)
            rr(z) = cc.Caption
            z += 1
        Next
        Dim f As Integer = rr.Length - 1
        For Each cc In ss.Columns
            For Each cr In ss.Rows
                ReDim Preserve rr1(k)(f)["IndexOutOfRangeException was unhandled"error ]
                rr1(k)(m) = cr(cc)
                k = k + 1
            Next
            If m < f Then
                m = m + 1
            End If
            k = 0
        Next
        For Each cc In ss.Columns
            If cc.Caption = "ID" Then
                For Each cr In ss.Rows
                    ReDim Preserve id(j)
                    id(j) = cr(cc)
                    j += 1
                Next
            Else
                For Each cr In ss.Rows
                    ReDim Preserve attr(rr1.GetUpperBound(0) - 1)(i)
                    attr(d)(i) = cr(cc)
                    If d < rr1.GetUpperBound(0) Then
                        d += 1
                    End If
                Next
                d = 0
                i += 1
            End If
        Next
    End Sub
Posted
Updated 14-Feb-15 13:55pm
v2
Comments
Dave Kreskowiak 14-Feb-15 19:55pm    
Next time, put your code snippet inside of HTML PRE tags so it retains it's formatting. Your code as it is now is pretty unreadable.
nadia marco 15-Feb-15 9:02am    
ok, thanks for the advice :)

1 solution

The problem is that you can only use Redim Preserve on the last dimension of the array. You cannot ReDim Preserve the first dimension in your code.
 
Share this answer
 
Comments
nadia marco 15-Feb-15 9:26am    
I tried to Redim preserve the last dimension of the array , but still have the same problem
Dave Kreskowiak 15-Feb-15 9:55am    
And how did you try to do that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900