LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a spreadsheet and do something according to its value

Solved!
Go to solution

Hello, 

i need to read a table in a spreadsheet with boolean and then accordingly to the value of the table, do some actions (if 1) or don't do any action (if 0). So i guess i need to send the spreadsheet into an array and then loop into the array elements, read them, and use the result as case input in a case structure. 

I am not a LabView expert though, so i don't know how to do it. Someone can help me? 

Thanks a lot 

stefania

 

0 Kudos
Message 1 of 12
(3,075 Views)

What do you mean when you say spreadsheet?  Do you refer to an Excel file (.xls or .xlsx) or do you have your data stored in a CSV or text file (comma or tab delimited) that can be read into most spreadsheet programs? 

 

If you are working with Excel files, you'll want to use the Report Generation Toolkit, which is a toolkit offered by NI that, in the past was sold separately but I believe is now included as part of a professional license. 

 

If working with CSV, there is a VI on the File I/O palette called Read from Spreadsheet File that will read the file into an array, using the character that you specify as the delimiter (most often a comma). 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 12
(3,043 Views)

Hi, thanks aputman, 

CSV is good for me. The problem is once i read the file into an array, how i can loop through it and use each element as a case input for a case structure. I am not sure if I was clear enough. I guess it must be pretty simple, but i am new to labview and i am struggling with it!

Thanks again for your time

0 Kudos
Message 3 of 12
(3,040 Views)

Share with us what you have tried.  There are many ways to interpret what you have said.  If you can show us an example input file, and what you want to do with it, I'm sure you'll get a response.  

 

You'll most likely need a For Loop or While loop with auto-indexing turned on.  If your data is a 2 dimensional array, you may need nested For loops.  Again, your request is too vague to be any more specific.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 12
(3,033 Views)

On the first page of the Forum, there are links to LabVIEW Tutorials.  One of the earlier items covered is Arrays and how they interact with For Loops.  Spend some time (a few hours) with the Tutorials, try the things they tell you, reproduce the examples, do the exercises, and you will learn the elementary LabVIEW stuff you need to solve your own problem.

 

Bob Schor

0 Kudos
Message 5 of 12
(2,994 Views)

Hi, thanks a lot for the answers!
I wasn't clear (at all) in the first message, so maybe the best thing is to show you what I have done. Sorry for that.

I need to implement a program which interacts with arduino in order to use a glue dispenser. So in the program in attachment, i am looping over a boolean array and, according to the elements value, i pass to arduino different commands (this is what i was trying to say in the first message). 

My next step is to read from a csv spreadsheet and pass it to the array.

So in the spreadsheet i will have something like this for example:

 

000011111000000011111100000

1111100001111111100000111111

000011111000000011111100000

 

and then i need convert this to the array in the program. 

I've read the tutorial but i didn't know if my idea of proceeding was correct (i still don't know actually if there is a way to optimize it since it is my first program 🙂 ). 
Another think i need to do is as i loop over the vector, i change the color of the round led marking in this way that i have processed the element. This i have no idea on how to do (and if it is possible). 

Thanks for your time anyway.  I really appreciate it. 

 

 

0 Kudos
Message 6 of 12
(2,965 Views)
Solution
Accepted by topic author Stefis84

@Stefis84 wrote:

My next step is to read from a csv spreadsheet and pass it to the array.

So in the spreadsheet i will have something like this for example:

 

000011111000000011111100000

1111100001111111100000111111

000011111000000011111100000

 

and then i need convert this to the array in the program.


So no commas in a Comma Separated Values file?  Does not really matter.

 

Based on what you showed here, I would use the Read From Text File.  Right-click on it and you will see an option to "Read Lines" or something like that.  Enable that and set the number to read to -1, which will read all of the lines.  The output is now an array of strings.  Now you can just autoindex on the line, parse it, and send it along.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 12
(2,952 Views)

Hi, 

thanks again for helping me. 

I have tried this solution, although for example if i have a file as the one in attachment, it gives me the wrong pattern (also in attachment). 

Thanks 

stefania

 

Download All
0 Kudos
Message 8 of 12
(2,938 Views)

I see. It takes the coma also. I need to manipulate a bit the string. 

Thanks again for the help 🙂


0 Kudos
Message 9 of 12
(2,927 Views)
Solution
Accepted by topic author Stefis84

Hi Stefis,

 

what's your problem with using the ready-to-use Spreadsheet file functions in LabVIEW?

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 12
(2,914 Views)