I have the following code to read a .csv file that contains two rows of data. I do not know what is wrong with it. How can I improve it to read a .csv file with two rows of data
As for parsing a CSV file, you are likely better off using a library (user-defined functions), especially if you e.g. have complex CSVs with quoted strings (commas inside of the "cell"/string) or line breaks, which are hard to handle.
The best I can recommend is CSVSplit.
Basically you have a function _CSVSplit
that takes a whole CSV file (content, i.e. string!) and returns you a two-dimensional array:
Local $sCSV = FileRead($sFilePath)
If @error Then ; ....
$aSplitArray = _CSVSplit($sCSV, ",")
You can then do everything you want with this array. Obviously, CSVSplit also provides the "reverse" function for turning an array into a CSV string again, _ArrayToCSV
.