06-22-2009 04:00 PM
Hello,
I am trying to write a code that reads a data from a spreadsheet file, which has multiple rows.
The recorded data has a formatting that looks something like:
Test Serial | Data1 | Data2 | Data3 | .....
SN1 | ## | ## | ## |.......
SN2 | ## | ## | ## |.......
and so on.
What I'd like to do is to determine the test serial number of the last measurement by reading the number that immediately follows "SN" from the last line of the file(e.g. 2 for the example above).
This must be quite simple, but I have never done this before so I need some help.
I tried putting "SN%d" for "format string," but I keep getting an error from the source"Scan From File (arg 1)."
Does "scan from file" only work for a file with one row? If so, how do you isolate the last row and make it scan from that line?
Thanks in advance.
Solved! Go to Solution.
06-22-2009 04:21 PM
You can make use of the "Index Array" function on your 2-D array to pull out certain rows out of you array. Use this in conjunction with the "Transpose" function to pull out columns. Use the "search 1d array" for your functions as well. I am unsure the delimiter characters you need to use though.
06-22-2009 04:21 PM
HI,
ASCII files do not support random access. read the entire file and extract the last row of the data. Then usematch pattern to isolate the numeric field from the SN field. Post back for queries.
06-22-2009 05:49 PM
Thanks to both DoomPirate and JK,
Here is the thing. The way the data are recorded is using "write characters to file" and "build array" with "tab constant"/"carriage return constant."
So when I use "read characters from file" or "read lines from file," it gives me everything in one big string indicator, instead of in array form with separate index. Here is the main question: How do I extract the last low of the data in this case?
Thanks.
06-22-2009 06:00 PM
06-22-2009 06:39 PM
Thanks again to DoomPirate, JK, and smercurio_fc.
I ended up solving the problem by first changing the formatting of the recorded data so that it only records numbers instead of "SN#" to use "read from spreadsheet file" which only reads numerical data. And then I transposed the array so that all serial numbers are in the first row. Then I extracted the first row (that contains serial numbers) using index array, reversed array so that the last serial number becomes the first, and finally, used index array again to read the first serial number (which actually is the last).
Everyone helped and inspired me by the equal amount, so I want to mark all the replies as solutions, but I am allowed to choose only one. So I am choosing the DoomPirate's answer because it is the first reply. I gave kudos for everyone.
Thank you.
06-22-2009 11:23 PM - edited 06-22-2009 11:23 PM
What version of LabVIEW are you using? In LabVIEW 8.x the Read From Spreadsheet File is not limited to just numbers. It is polymorphic and can be set to read strings. You are also doing more work than you need to do. You do not need to transpose the array just so you can pull off the first row to get the serial numbers. You also do not need to reverse the array. Are the serial numbers sequential? If so, you just need the number of rows which you can get from Array Size. Then the last serial number is the number of rows less one (for the header). If they are not sequential, you just need to pull off the last element in the first column.
If we assume LabVIEW 8.x, then your code could look like this:
If you are using LabVIEW 7, open the Read From Spreadsheet File. It explains how to modify the VI to have it return strings instead of numbers. If you do this, be sure to save it as a new VI.
06-23-2009 10:54 AM
Thanks smercurio_fc.
I am using 7.0 in my company, but we just ordered 8.6 so it should be here soon. When we upgrade it, I'll try your suggestion.
Thanks.