'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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
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
TimCotteeHead of Software ServicesCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.