LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to I write line to a text file?

What is equivalent of WriteLine function in Labview? I want to write line to a textfile? (LIne by line).Another word I want to write first line then write sedond line and so on..
 
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 9
(8,219 Views)
Far as I know, there's not a built in function for this, but I think it's pretty simple to make.  Just append a CR/LF at the end of each line, and then use whatever write to file VI you wish (text, etc.  If it's a spreadsheet it's a different story).

If you're using LV8, then you may have to use the "Get File Position" and "Set File Position" vis in conjunction with the write.

Anyone know the overhead of have three file writing VIs in a loop that has many iterations?  (Set Position->Write to File->Get Position, repeat)

Message Edited by Novatron on 06-30-2006 09:02 AM

0 Kudos
Message 2 of 9
(8,214 Views)
If you don't explicitly set the file position, then LabVIEW will simply use the current file position (where you last stopped writing or reading). Therefore you don't always have to get and set the file position in LabVIEW 8. If you want to write three lines, just use three Write to Text File VIs with CRLF's at the end of each text line.

The VI attached below should show what I mean. Hope this helps!
Jarrod S.
National Instruments
Message 3 of 9
(8,194 Views)

Thanks Jarrod,

That will work.

Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 4 of 9
(8,176 Views)
Different approach. Open the file up, move the file position to the end, append the line then close the file.
 
 
Example is LV8
 
David

Message Edited by David Crawford on 07-06-2006 03:23 PM

Download All
Message 5 of 9
(8,162 Views)
That's true. This approach is necessary if you are closing and reopening the file between write operations.
Jarrod S.
National Instruments
Message 6 of 9
(8,138 Views)
That is the biggest pain in the ass.  I'm doing just that sort of thing, except I have 110 lines or so.  It has to be a very specific format, and each line must take some input text.  Isn't there any easier way to do this?  I am almost tempted to use the CIN function and create the code in C, but that's just a whole other adventure itself. 
0 Kudos
Message 7 of 9
(8,052 Views)
Have you seen the VI called Format Into File? That will allow you to build together various lines of input and write it directly to a file. This operates much like a printf function in C in terms of syntax, so you should be able to do the kinds of things you're familiar with in that language.

The example above outputs:

0.636, random text, 0.5
0.720, random text, 0.9
0.155, random text, 0.7
0.863, random text, 0.5
0.528, random text, 0.3
0.663, random text, 1.0
0.244, random text, 0.9
0.604, random text, 0.3
etc...

Message Edited by Jarrod S. on 08-10-2006 03:57 PM

Jarrod S.
National Instruments
0 Kudos
Message 8 of 9
(8,042 Views)
Jarrod S.:

If you need to re-write to specific line in the file, you read it as spreadsheet (if you have some kind of separator) and then delete the changed array row/column from the array and insert it back with changed data.
After that you write it back to spreadsheet file.

Prolly the best way to do it.
0 Kudos
Message 9 of 9
(7,843 Views)