cancel
Showing results for 
Search instead for 
Did you mean: 

Reading text file

SOLVED
Lab V
Member
Solved!

Reading text file

Message contains an attachment

I am trying to read the text file. The text file is having multiple lines of text. I am using Read from text file function available in the file I /O.  

 

Please find attached the 2 snapshot of the block diagram. Image 1st (i.e txt1) is working perfectly i.e. it is reading all the lines available in the text file. But VI shown in the second image (i.e txt2) is showing only first line of the text file. I am using the same function in the both VI i.e. read from text file

 

Question :-

 

1)      what is difference between the two “Read from text file” function

2)      how to make the second VI working same as the first one?

6 REPLIES 6
Harold_Timmis
Active Participant

Re: Reading text file

Message contains an attachment
use the read from spreadsheet function and here is an example of that:
Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcomeSmiley Happy
Dennis_Knutson
Knight of NI

Re: Reading text file

Can't debug a picture.

 

Do you have lines or characters selected. Are you reading the same file with both functions?

 

Attaching the two VIs and the text file(s) would help you get the question answered.

Lab V
Member

Re: Reading text file

Message contains an attachment

Hi All ,

 

I have attached both VIs & the text file I am trying to read. Readtxt1.vi will read only the first line of the text file where as the readtxt2.vi will read the full text file.

 

In both the case I am using read from text file function but result are different . My queries are

 

 

1)      what is difference between the two “Read from text file” function

2)      how to make the second VI working same as the first one?

 

 

Thanks in advance

LabV

 

 

RavensFan
Knight of NI
Solution

Re: Reading text file

Message contains an image Message contains an attachment

Right click on the VI and you will see an option in the right click menu for Read Lines.  I suggest hitting Ctrl-H and turn on context help to look at this function.  Go into detailed help for more details.

 

If you're reading lines, then you get an array of strings.

 

By the way, it makes no sense to have a while loop around your Read functions.  And even less sense to have the Cancelled output wired to the stop terminal of the while loop.

 

 

 

Changing the Read Lines and checkmark and wiring the "count" input shows there might be a bug with the way this Read Text File VI is configured.

 

1.  With count unwired,  either Read Lines or Not is wired just fine to the string indicator.

2.  With Read Lines not checked, create a constant for count.  It is wired just fine to the string indicator.

3.  With Read Lines checked, create a constant for count.  The output wire breaks because it is an array of strings going to the string indicator.

4.  Uncheck Read Lines.  Constant is still wired.  The output wire remains broken.  Why?

5.  Leave Read Lines unchecked.  Delete the constant.  The output wire fixes itself.

6.  Leave Read Lines unchecked.  Recreate the constant.  The output wire remains just fine.  Although the setup is now the same as #4, it is all wired like it should be.

7.  Go in and check Read Lines.  The constant is still wired.  The output wire remains just fine.  Why?  Although the setup is the same as #3, the wire is okay even though it shouldn't be.

 

It is like the compiler only checks the wire data types if you create constants.  Not when you change the Read Lines setting on the VI.  Only if you try to run the VI in #7 will the VI break, give you and error, and show you the broken wire.  I would consider this a bug.  (Interestingly, I had to do a screen capture to get this screenshot.  Using the code capture tool forced a compiler check that made the lower two wires fixed or broken as they should be.

 

 

Message Edited by Ravens Fan on 07-01-2009 02:37 AM
Highlighted
Lab V
Member

Re: Reading text file

Thanks A lot All especially Ravens Fan

 

 

TCPlomp
Trusted Enthusiast

Re: Reading text file


Ravens Fan wrote:
......

I would consider this a bug.  (Interestingly, I had to do a screen capture to get this screenshot.  Using the code capture tool forced a compiler check that made the lower two wires fixed or broken as they should be.

 

Cool you can use the Code Capture Tool to debug fix your code!

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!