CSVFileToArray
CSVFileToArray>CSVFile,ArrayVariable
Reads the given CSV file into a multi-dimensional array.
The array takes the format:
arrayname_row_col
arrayname_row_count
arrayname_count
E.g. the following CSV data will produce the array variables given below:
CSV Data:
ID,Date,Value
1,28/02/2010,50
2,01/03/2010,75
Code:
CSVFileToArray>c:\myfile.csv,csvData
Array:
csvData_1_count=3
csvData_1_0=ID
csvData_1_1=Date
csvData_1_2=Value
csvData_2_count=3
csvData_2_0=1
csvData_2_1=28/02/2010
csvData_2_2=50
csvData_3_count=3
csvData_3_0=2
csvData_3_1=01/03/2010
csvData_3_2=75
csvData_count=3
Note: The column count starts at 0. i.e. column A is 0, and not 1.
Thus :
csvData_1_0 returns the contents of Row1 Col1
csvData_1_1 returns the contents of Row1 Col2
Note that it is also possible to read CSV file data into an array using DBQuery with a suitable CSV file connection string, but CSVFileToArray is less format sensitive and can cope with rows with different field counts. There are pros and cons to both methods. DBQuery can retrieve the data more selectively whereas CSVFileToArray reads in the entire file.
Example
CSVFileToArray>c:\temp\test.txt,csvData
If>csvData_count>0
Let>row=0
Repeat>row
Let>row=row+1
Let>field1=csvData_%row%_0
Let>field2=csvData_%row%_1
Let>field3=csvData_%row%_2
MessageModal>%field1% %field2% %field3%
Until>row=csvData_count
Endif