I’m currently using the following code in xojo to populate an array usingg elements from a CSV file, and later assign the results to variables. It works pretty well.
For row as integer = 0 to UBound(CSV_Array)
dim rowData as string = CSV_Array(row)
CSV_Line_Array() = Split(rowData, “,”)
What I’d like to do is, rather than using the index number for an array element, is to use the values of the column. Something like this (obviously this code doesn’t work)
The reason I want to do this is so that when I read in the CSV file, it no longer will matter what order the columns are in, and instead of column position, it relies on the header value. I’m not sure how to get here. Any suggestions?
I don’t see how that solves my core goal… which is allowing the import file columns to be in any order the user presents them in. Storing the data is trivial, it’s accessing it by column header value prior to normalization and storing that I’m trying to achieve.
Use the header data to determine the SQLite field names, and order becomes unimportant. SQL cares not what order the data came in, nor the order in which it goes out.
Kem… an Enum would require the order of fields be known ahead of time…which it seems is the issue… the any input file could contain the fields in any order left to right, assuming I am understanding the “core goal” here
So my final code is this… Working great (I run this before the line by line parsing of each line in the CSV file, so this just focuses on the header row)
[code]For row as integer = 0 to 0
dim rowData as string = CSV_Array(row)
dim header() as string
header = Split(rowData, “,”)