'Redim' statement requires an array error

Hi,
I am experiencing this error "'Redim' statement requires an array"
I am declaring array as dim array1 as array.
using vb.net/.net2.0
Thank you
Function xyz(......)as class1
        dim booklog as new class2
        dim array1 as array
        Dim member As DataRow
        Dim i As Integer = 0
        array1 = booklog.Retrivetech(intid, stress)
        For Each member In array1
            Dim ob As New dire.class2
            ob.address = CStr(member.Item("address").ToString)
            ob.name = CStr(member.Item("name").ToString)
            ReDim Preserve array1(i)
            array1(i) = ob
        Next
Return array1
    End Function

Open in new window

tracy_pAsked:
Who is Participating?
 
TimCotteeConnect With a Mentor Commented:
Your function is declared as returning an object of type "Class1" but you are trying to return an array of something else!

I would perhaps do something along these lines instead, using the arraylist object rather than an array.
    Function xyz(......)as arraylist
        Dim alResults As ArrayList = New ArrayList
        dim booklog as new class2
        For Each member As DataRow In booklog.Retrivetech(intid, stress)
            Dim ob As New dire.class2
            ob.address = CStr(member.Item("address").ToString)
            ob.name = CStr(member.Item("name").ToString)
            alResults.Add(ob)
        Next
        Return alResults
    End Function

Open in new window

0
 
TimCotteeCommented:
I cannot follow what is happening in this function at all!

You are not declaring array1 as anything (at least not in the posted code).

array1 looks like it is actually an array of datarow() .

As you iterate through the array1 elements you seem to be trying to redimension the array you are traversing and changing the value of the element you are looking at.

I am surprised that this doesn't give you more errors than you currently see!

If you can explain what the function is supposed to do and what it is that the various classes represent we may be able to advise you how better to achieve your aim.
0
 
tracy_pAuthor Commented:
I am sorry.
there is a mistake in code
dim array1 as array.------is the correct line(line 3)

in this function ,i am trying to call a function(Retrivetech) from another class(class2) and i am looping thru the columns.
thank you.
0
 
tracy_pAuthor Commented:
when used the above code,this is the error i am getting.
value of type 1-dimentional array' booklog.retrivetech 'cannot be converted to System.collections.arraylist

Thank you
0
All Courses

From novice to tech pro — start learning today.