From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

EOF detection in "Read From Spreadsheet File"

Solved!
Go to solution

Hi folks,

 

I need help in detecting EOF in a "Read From Spreadsheet File". I' d like to stop a while loop by wiring the EOF? indicator to the stop condition, but this doesn't work. For design resons I can't substitute the while loop with a for loop and I DO need the while loop. I read something about creating custom EOF detection but I'm wondering why the builtin function in the vi doesn' t work and if there isn't some simple solution.

 

Many thanks,

 

hazibuli

 

0 Kudos
Message 1 of 13
(3,986 Views)

Post images of your code so we can follow your question.

 

EOF will be returned when reading a file line by line etc. and I have worked with same in my apps, so I suspect you are missing something.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 13
(3,981 Views)

This is a sample code along with text file I try to read.

 

 

Download All
0 Kudos
Message 3 of 13
(3,975 Views)

That VI makes no sense. You read the entire file and since you have not specified the number of lines, you will not be reading past the EOF. Since you will never read past the EOF, the while loop will never stop.

 

Explain what you really want to do because the code is just plain wrong.

0 Kudos
Message 4 of 13
(3,962 Views)

I just want the while loop to stop automatically as soon as all the lines have been read in, but without specifying how many lines the file contains since this is not fixed. How can I do that?

0 Kudos
Message 5 of 13
(3,956 Views)

You've already done that. Did you read the help for the function? Silly question. If you had, you would have seen that if you leave the number of lines unwired, it will automatically read the entire file. You have it unwired so the 2D array output is the entire file. The while loop is completely unnecessary. Simple enough? Even if you were to wire up the number of lines input, you would have to place the function inside a while loop.

 

Please take the recomended tutorials and always work with context help turned on and read the help before posting a question.

0 Kudos
Message 6 of 13
(3,950 Views)

Indexing the 2D array by means of the while loop allows me to read one line at the time. Is that correct? This is what I need. For loop would work fine but I need some control to step out of the loop if something goes wrong before the whole file is read in.

0 Kudos
Message 7 of 13
(3,942 Views)

right-click the For loop and show the "Condition Terminal" (applies to modern version of LV only).

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 13
(3,933 Views)

hazibuli wrote:

Indexing the 2D array by means of the while loop allows me to read one line at the time. Is that correct? This is what I need. For loop would work fine but I need some control to step out of the loop if something goes wrong before the whole file is read in.


 

NOOOO. Indexing the 2D array has nothing at all with reading the file! The file is already completely, totally, read.

 

Why do you think you need to read one line at a time? What could go wrong by reading the entire file all at once. What would be your 'go wrong' conditions? It really sounds like you are making things much harder than they have to be but then again, you have really not provided any details on what you want to accomplish.

 

 

0 Kudos
Message 9 of 13
(3,931 Views)

I'm guessing that you want to process one line at a time from the spreadsheet.  Use Read From Spreadsheet File to read in the entire spreadsheet as Dennis says.  Then wire the 2D output to a For Loop with indexing enabled.  Each iteration of the For Loop will allow you to process one line at a time.  When the last line is processed, the For Loop will exit automatically.  Here is an example to get string length of each element in a spreadsheet.

 

ReadSpreadsheet.png

Message Edited by tbob on 03-15-2010 09:46 AM
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 13
(3,911 Views)