Link to home
Create AccountLog in
Avatar of ITranger
ITranger

asked on

How do I use Arrays?

Hi All,

I'm a bit confused with the whole array business.

I'm trying to gather all the recordID's in an array after a search result so a user can navigate through it using array functions.

Now, after all the other code - I'd like to read the recordID into the array like so:

        Do While dr.Read()

              ' Add  dr.Item("RecordID") to  RecordIDArray()

            Loop

How do I initialise an array I don't know the length of and how do I add values to it as this loop loops!?
SOLUTION
Avatar of cubixSoftware
cubixSoftware

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ITranger
ITranger

ASKER

Thanks for your reply.

After some more reading I did this:

            'Read the results into an array
            Dim i As Integer = 0
            Dim RecordIDArray() As Long
            Do While dr.Read()

                ReDim Preserve RecordIDArray(i) '<--- ReDim and Preserve, this re-dimensions the array, preserving the stored values! :)
                RecordIDArray(i) = dr.Item("RecordID")
                i += 1

            Loop

This seems to work well! Arrays seem so much more complex than that of PHP - prob because they're more powerful so best get reading :)

So which method do I use? I like the above as it's more like what I'm used to with a thrown in 'ReDim Preserve'!
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Ah cool,

I did try that but missed out the 'New' keyword - no wonder it didn't work!!

ArrayList it is then!!!

Thanks