LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read txt file

Hi, i wanna to read lines from a txt file. I got a switch fucntion requirment as well. When 1 is selected, the program needs to read the lines form the beginning of the txt file. For example, if, at the momone, 2 is selected, the program will plus 5 lines, and continue to read the txt file (e.g., 1 is reading the 10th line at the momoent i switched it to 2, then 2 will begin from the 15th line and continue to read the file. And, in contrast, if the 2 is reading the 15th line, i switch it to 1, then 1 will immediately read the txt file from 10th line). Now, i need to got a switch includes 1,2,3,4. Every interval is 5 lines. How can i do it?

Message Edited by connoryz on 02-17-2006 04:30 AM

0 Kudos
Message 1 of 7
(3,504 Views)

Good morning connoryz,

Let's review your posting so that i can better understand what you wish to achieve.

The first question is:  Is the text file to be read exactly the same as the one attached?

So, you want a vi that, when 1 is selected, it will read line by line from the last point that it read.  newline = previous_line + 1.  Is this correct?  Only when the vi is started that it starts reading from the beginning of the text file.

At any moment, whe n the selection is 2, it the jumps 5 lines from the previous position in the text file.  newline = previous_line + 5.  Is this correct?  What happens if the switch is at selection 2 when first running the vi?  Does it read line 1, then line 6, 11 and so on? Or rather, it only jumps once, from line 1 to line 6 then continue to line 7, 8, 9, until the switch is reset (selection 1) and then back to selection 2..  Actually... no... from re-reading your text, if you switch back to 1 it returns to line 1 (back 5 lines) plus 1 = line 2, so it has to keep track of the previous state, is this correct?

Your implementation will actually have 4 selections..  Does each selection multiply by 5? 

ie: selection 1 is increment 1 line,  selection 2 is jump 5 lines,  selection 3 is jump10 lines,  selection 4 is jump15 lines.  Then increment by 1 line until a change in selection is made.  So, can you select 1, then 4 and immediately jump 15 lines?  If not, then maybe all you need is a button that says "JUMP 5 lines" and another button "GO BACK 5 Lines"... 

I can create an example of the code... but I need to fully understand what you want to achieve because the approach may be different.

Regards,

JLV

 
Message 2 of 7
(3,468 Views)
thanks a lot. hehe.
 
for the simplest case for this question. the value is set as 1 at everytime.
 
the explaination you stated is what the meaning i wanted to say.
 
i give a txt file, a vi program. when i start the program, it reads from the first line. then when i select 2,3,4 seperately, it will have the following equations: previousline+5, previousline+10 and previousline+15. If the sensor goes to the end of this txt file. it will go back to the first line and re-read from beginning.
 
thanks.
 
I am trying to read the whole  data from the specified txt file using "Read from spreadsheet file" vi, then use the "Index Array" vi to specify the line i wanna to get. could i do a part of program in this way? hope to have a look of your example code. thanks!! 
0 Kudos
Message 3 of 7
(3,454 Views)
this is a better txt file for this problem. thanks.
0 Kudos
Message 4 of 7
(3,453 Views)
any help?
0 Kudos
Message 5 of 7
(3,444 Views)

Sorry..

I was away..

I am preparing an example vi.  Should be available soon.. 

😄

Message 6 of 7
(3,412 Views)

Hi connoryz,

Here is an example in it's most basic form.

I left the echo of the text file at the bottom of the front panel for debugging purposes.  It is set to display "\" codes.

There are some comments in the block diagram.  I have to go to a meeting.. 

The file is selected at run time, so you do not have to place both in the same folder... although it is easier that way.

Hope it helps.

Ray

Message Edited by JoeLabView on 02-20-2006 09:54 AM

Message 7 of 7
(3,401 Views)