LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read CSV into LV as Text

Solved!
Go to solution

I have a .csv file which I would like to read into a 2D array in LV. The file is a mix of text and decimal values. I have attempted to use the "read from spreadsheet file" however it changes all text values to 0.00. I have tried to set the format of "read from spreadsheet file" to string (%s) but to no avail.

 

After several hours of searching these and other forums for a solution I have come up empty handed.

 

I look forward to hearing you thoughts.

 

Thanks a bunch!

0 Kudos
Message 1 of 8
(4,176 Views)

If you post a copy of your VI and a copy of your CSV file, we maybe able to help you.

 

If you have a mix of text and decimal values, how do you want them to appear in LabVIEW.  A 2-D array can only be numerics or strings, not both.

Message 2 of 8
(4,148 Views)

Do you have a reliable way of distinguishing which parts of the file are text and which are numeric data?  Are they mixed on the same line or always on different lines?  Do the text lines have some unique characters, preferably at the beginning or ending of each line?  In other words do you have the format definition of the file?

 

Usually it is necessary to separate the text parts from the data parts using string functions and then either the string to number formatting functions or the Spreadsheet String to Array  can be used to convert the numeric data strings to numbers.

 

Lynn 

Message 3 of 8
(4,147 Views)
You DO NOT read text by changing the format to %s. You read everything as text by selecting the polymorphic selector below the function. If you do not have the polymorphic selector, you have to modify the VI per the instructions on the block diagram.
0 Kudos
Message 4 of 8
(4,139 Views)

Thank you for your help!

 

There isn't much to the code. What I have described is my starting point.

 

The data is formatted in such a way that I know very reliably what is text and what are numbers. From the suggestions you've made I plan to read in all values from the csv as text. When I need to treat a value as a number I will convert it.

 

The data is similar to this in content but with many more fields:

 

Test 1, Test 2, Test 3

Yes, Yes, No

34.8, 42.6, 45.0

0.02, 5.43, 2.1

 

Is there a way to read two delimiters "," and newline?  I suppose the "Scan String for Tokens" could be used. This would allow me to mimic the "read from spreadsheet file" function but for text values.

 

What do you think?

 

Thanks again for the help!

0 Kudos
Message 5 of 8
(4,117 Views)
Solution
Accepted by topic author jake1010

I did some more searching around and came across this post. It explains how to copy and modify the "Read from Spreadsheet File" to create arrays of strings instead of numerical values.  All my data reads into lab view as text and I will simply convert text numbers to actual numerical values as needed.

 

Thanks again!

0 Kudos
Message 6 of 8
(4,106 Views)
I don't know why you had to do any searching. The directions on the block diagram are what are in that post.
0 Kudos
Message 7 of 8
(4,088 Views)

True statement Dennis.  And in addition to that the post provided the idea that one could solve the problem in that manner. Something I hadn't discovered (nor had been suggested here).

 

Thanks again for your help!

0 Kudos
Message 8 of 8
(4,080 Views)