Need help with array/table processing

  1. 3 months ago

    Jim B

    Feb 18 Folsom, CA

    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
    next

    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?

    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!

  2. Dave S

    Feb 18 San Diego, California USA
    Edited 3 months ago

    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
    temp.field1=stuff1
    temp.feid2=stuff2
    myArray.append temp
    next i

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

  3. Jim B

    Feb 18 Folsom, CA

    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.

    Jim

  4. Dave S

    Feb 18 San Diego, California USA

    No there is no such restriction...

  5. Jim B

    Feb 18 Answer Folsom, CA

    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!

or Sign Up to reply!