Reading a csv file in PAC control

I am trying to import a table from excel (a csv file) to a numeric table in PAC control. I was trying to use a communication handle and according to the status the communication handle was opened just find. I was trying to use the “ReceiveNumTable” command.

Any help would be appreciated
Thanks

Does your csv file have multiple rows and multiple columns? A numeric table in PAC Control is only a single dimension, so you may need a numeric table for each column in your CSV (Depends on what you want). Can you post a sample of your data and how you want it stored in PAC Control?

Yeah my csv file has two dimensions, It has two columns and about 50 rows. I do want separate numeric tables for each column. My data is pretty simple, the first column is list of masses and the second is a list of lengths. All I want done is the first column in my csv to be in its own numeric table and the second column to be in another.

Thanks

Keep in mind, your file is made of strings that represent your data, so you’ll likely want to use the SetEndOfMessageTerminator command so your delimiter is a comma.

Next you’ll use the ReceiveStrTable command to pull your file into on long string table where each element is one value, then loop through and use a command like StringToFloat or StringToInt32 to convert each of those strings into the data type you really want.

Mary has an example of parsing a file here:

With few modifications of the above code you should be able to parse down into individual rows (or use the ReceiveStrTable command as Mary mentioned and loop through the string table). Once you have a single row, you will need to parse the individual rows for the comma, convert from string to float (there’s a command for that) and then store in your table.

I have a subroutine I use to parse strings that takes a delimiter as a parameter and a position and returns the parsed item which will help with parsing at the row level:

ParseDelimitedString.zip (1.2 KB)

You would call it like this:
ParseDelimitedString(MyRow, “,”, 1, FirstColumnValue);
ParseDelimitedString(MyRow, “,”, 2, SecondColumnValue);

This returns strings, so you will then use the StringToFloat command and store in your table.

Good luck!

Thanks, Philip! You’re the best!!