LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to stop a while condition when I read a EOF of text file

Hi,
I just want to stop a while condition when I detect the End of file.
I attach a example.
Thank's a lot for your help.
0 Kudos
Message 1 of 11
(6,197 Views)
Try using the "Read Characters From File.vi". It opens, reads and closes a file. It has an output that goes true when you read the EOF. I have changed your example a little and attached it here.

Rob
0 Kudos
Message 2 of 11
(6,197 Views)
Thank's Rob for your answer
but, I don't want read antire file.
I want to:
-Open file
-Read one String
-Analysing the String
-Test if Eof
-Read one String
-Analysing the String
-Test if Eof .....etc
-If Eof is True then closed file

Thank's
0 Kudos
Message 4 of 11
(6,197 Views)
If each string is terminated with the EOL character, then you can read one line at a time. I have changed the example to read one line at a time until it gets the EOF. There is an input in Read Lines from File.vi that lets you tell it how many lines to read.

Rob
0 Kudos
Message 8 of 11
(6,197 Views)
Thank's Rob.
I found a solution in my example but I don't understand why I must Open and Closed the file every loop..?
Thank's
0 Kudos
Message 10 of 11
(6,197 Views)
Read Lines From File.vi on the File I/O palette is an example for how this is done. In fact, you might just want to use this VI instead of your own if the file has a large number of lines. As the comment at the bottom of the VI states, using the string contatentation is not very effecient for more than a few lines.
0 Kudos
Message 3 of 11
(6,197 Views)
Hallo

I ran into the same problem several times.
It's just the way a while loop works. It's annoying but...
If I read into an array with autoindexing I keep a count of how many reads I did and delete the last entry. Or you'll have to insert a if-case inside the loop and process only if there was no EOF.

Using the high level routines in loop is certainly no way. Open-read-close-open-read-close-open-read..... is a certain performance killer.

Gabi
7.1 -- 2013
CLA
0 Kudos
Message 5 of 11
(6,197 Views)
Please look attached vi.
Good luck.
0 Kudos
Message 6 of 11
(6,197 Views)
Thank's
But I can't read One line-->analyse the string-->test the Eof-->read One line--> etc...
If you have the solution!!!
Thank's
0 Kudos
Message 7 of 11
(6,197 Views)
If you read line by line you can't know if this is last line because LabVIEW don't put the EOF symbol to data. Last symbol always is Line Feed. In vi that i attached i compare each symbol with empty string, because only this way you can know if you reached EOF.
0 Kudos
Message 9 of 11
(6,197 Views)