LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Text File Line by Line

Hi all,

I would like to take numbers from a text file and read them line by line. Eventually I'd like to store them in an array but for now how would I read each line individually and then move onto the next line? Thanks!

0 Kudos
Message 1 of 6
(3,319 Views)

You can use the read from spreadhseet VI to read the file and return and array of your values.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 6
(3,316 Views)

In addition to Mark's suggestion, if you truly want to read line by line, you can right click the read from text file VI and in the right click menu there is an option to do this. I believe reading the file all at once is more efficient though, probably due to memory allocations. If you only want specific lines and that is your main motivation for reading line by line, you could read the whole file, then discard the lines you don't care about.

0 Kudos
Message 3 of 6
(3,312 Views)

@for(imstuck) wrote:

I believe reading the file all at once is more efficient though, probably due to memory allocations



This is true to a point. If the file is very large you should read it in chunks. Reading a large file (> 1MB) all at once will be very slow.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 6
(3,295 Views)
Thanks for reminding me of this. I actually had a coworker who had to do this recently. I may also refactor some of my recent code to try and see if I can make it more efficient by doing this
0 Kudos
Message 5 of 6
(3,289 Views)

@for(imstuck) wrote:
Thanks for reminding me of this. I actually had a coworker who had to do this recently. I may also refactor some of my recent code to try and see if I can make it more efficient by doing this

It has been a while since I analyzed this and I am not certain that the 1 MB threshold is where you see performance hits. Some experimentation might be necessary to find the optimal point. In our code we took the easy approach and generally read in blocks of 10 to 20 KBs. This seems to give us good performance. Large blocks sizes may work as well but our timing didn't show significant differences between 1KB, 10 KB and 20KB block sizes. Disclaimer: What you do with those blocks could affect your performance but the execution time was basically the same in terms of simply reading the file.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 6
(3,261 Views)