Need help with array/table processing

Hi - my brain hurts from trying to figure this out so I’ve finally decided to ask for some guidance. I have a two dimensional array that I want to populate from records read from a flat text file. I’ve used the redim statement to size the array. As I read through my text file I increment an index variable for each record and want to use that as the “pointer” to the array entry. If I try to put data into each array entry using my variable, I get nothing. But if I enter a numeric literal instead of the variable, it works. An example of what I’m talking about:

dim MyArray(-1, -1) as text
dim some_text as text
redim MyArray(number_of_records_in_the_file, 7)
for i = 0 to number_of_records_in_the_file - 1
get some stuff here from the input file…
MyArray(i, 0) = some_text

What I get with that code is nulls in the array. If I change it for example to
MyArray(1, 0) = some_text

then I get whatever is in some_text placed into the array.

Am I doing something wrong, or is it not possible to use a variable to “loop” through an array?

what you posted looks like is should work… so I would bet there is something else going on…

I don’t know your intent… but perhaps instead of a 2D array of Strings (don’t use Text [my opinion])
why not create a custom class and create a 1D array of that

this is just to illustrate, and not meant as a cut/paste solution

// assume you made a class [myClass] that matches the data in your flat file
dim temp as myClass
redim myArray(-1)
for i=0 to number_of_records
// get some stuff
myArray.append temp
next i

or create an in-memory SQLite database and use a Table instead of array

Dave - thanks for the reply. Before I go off redoing the code, I guess I just need to know if there is any restriction on using a variable to index my way through the multi dimensional array.


No there is no such restriction…

OK - the problem has been solved. Pilot error. I’d accidentally changed a parameter used in the input file record identification, throwing off all my positional calculations. Changed it back the way it was supposed to be and the array processing code now works as I had wanted! It was actually working before but because of my error the array was being handed bogus data. Arrghhhh…

Thanks for your assistance, Dave!