LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to log string to a text-file?

Hello,

i have a program that creates results which should be logged into a file.

For this i execute:

Open File

Read From Text File

Then concatenate the read string with the new data

Write To Text File

Close File

 

Example in attachment

 

Now i execute this in a loop for two times but finally i have three lines in the file. And the first line is doubled.

 

Whats wrong here?

Is there also a soution to just add text at the end of the without having to read everything?

 

Thanks for help

0 Kudos
Message 1 of 4
(3,182 Views)

Hi One,

 

use those functions in that order:

  OpenFile

  SetFilePosition(EndOfFile)

  WriteText

  CloseFile

 

Easy like that…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 4
(3,176 Views)

Move your open/close outside the loop.

 

example[1].png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 3 of 4
(3,172 Views)

If i understood well this is what you want to do.

 

the thing is that you were reading the text from the file when you opened, and you were putting that text back in the file as a new line.

 

when you open a file that  has data already, the new data will append. so there is no reason to read the current data and rewrite it.

 

text file.png

 

thanks

CLAD, CTD
Message 4 of 4
(3,169 Views)