LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a txt file, load it, modify it and then save it again?

Hi Gerd,

As advised me, I've  created a seperate VI for loading my txt files. For that I used "System Exec.Vi. It works perfectly.

I'm still having problems with my txt file creator  VI. The solution you proposed me last time is creating "Batch File: 2.0" before every section.
I wanted it just one time. Just at the top of the file. A kind of a header. I've tried to modify my VI to  reach my goal but I'm not succeding. Any idea?

I have a another question which is related to txt files. I searched in the Forum but all the answers I found don't correspond to what I need.

Suppose a txt file with 5 columns of data (numerics or strings). If we use "Write to Text File" to save data, how  to create first, a main header (name of the file, date creation, name of the author and version) and, second,  a "secondary" header (Column1, Column2,......,Column5) on top of each column?

Thank you very much for your help. I appreciate it.
Kabanga

 

0 Kudos
Message 31 of 38
(1,501 Views)
Hi Kabanga,

see attached example...

You should use file refnums instead of file path. This way you can easily attach to existing files. (Read the context help for "writ eto text file"!)

So in your main vi you write the header (including "batch file: 2.0") and in the subvi you can append individual blocks of data...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 32 of 38
(1,498 Views)

Hi Gerd,

thanks a lot for your help. Everything is working perfectly !!!!!!!!!!!!!!

Best regards
Kabanga

0 Kudos
Message 33 of 38
(1,493 Views)

Hi gerd,

Thank you for making this topic so interesting for me. I have a question about your batch file sub vi.

You are using the "write to text file" block to create the desired txt file. When i using the same method as you, i can't accompish the same result.
I can see only the first value of the array in my txt file. I want to write to whole array in txt file. Can you help me please?

Thanks,

Jeroen

 

 

 

0 Kudos
Message 34 of 38
(1,471 Views)
Sorry, i forgot the attachments
Download All
0 Kudos
Message 35 of 38
(1,462 Views)

Hi Jeroen.

You could just wire the Array directly to the write text file.vi hence you do not need the for loop.  This will give you all the elements of the array in the same file.  What is your application? do you need this as a sub vi whereby it will be called from many places throught the program?

Craig

LabVIEW 2012
0 Kudos
Message 36 of 38
(1,454 Views)

Hi phuzionz

what is your application?
Have a look at the attached VI.
Is it what you want?

Best regards
Kabanga

0 Kudos
Message 37 of 38
(1,452 Views)
Hi Jeroen,

either use Kabangas example or use just file refnums - "write to text file" will append to files then! (See context help for this function.)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 38 of 38
(1,446 Views)