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?

Hello everyone!
I have a question and I hope you'll help me.
 
I'd like to create a txt file (please see attached pdf file) but I don't know how. I've tried many methods but it's not working  😞
The user should be able to change the parameters (for example "Time", "Time Type" ...etc) and the corresponding values from the Front Panel.
The number of section (Begin Line......End Line)  is 128.  Means, the final file should contain  "Begin Line1....End Line1"   till  "Begin Line128....End Line128".
Please, take a look at the attached file to see how does the structure of the file look like.
Note:  the seperator between a parameter (example, "Time") and its value (example, "7" in the section "Begin Line1....End Line1") is a colon( " : " ) and not an equal (" = ").
 
Thank you very much for your help.
Best regards
0 Kudos
Message 1 of 38
(5,311 Views)

I m a bit confused in that you want to write to a .txt file or .pdf file?

If it is the former, then you can use the Write Text File function from the File I/O pallette.

What version of LV do you use?

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 2 of 38
(5,291 Views)
Hi Kabanga,

as your text file consists of several similar blocks I would do:
1) read in the whole text file
2) convert it to an arrays of data blocks by searching for "begin line" and "end line"
3) convert each data block (in a loop...) into a data cluster using "scan from string" linewise (or use string search functions, when the user may change the order of the lines)
4) present the data cluster to the user to allow changes
5) when user has finished, convert data cluster back to text
6) write all text blocks to a file
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 38
(5,289 Views)

I recommand you to use a configuration file (*.ini with sections and keys) because this would greatly simplify the task !
See the functions palette >> File I/O >> Configuration File VIs and this extract from the LabVIEW help.

 
0 Kudos
Message 4 of 38
(5,288 Views)

Hi

thanks for your answers.
I'm using LV 8.2  and my file should be saved in txt.
Initially the file doesn't exist. So, the user choose the parameters and their values from the Front Panel
and then hit a button to create that file. The user should be able to reload (Front Panel button) the created file, modify it or not and then resave it.
Before hitting the "create file" button the user define (on the Front Panel)  the number of sections ("Begin Line.....End Line") to be created.
I joined a VI here just to explain the idea. May be that can help you to help me.
I appreciate yoyur help!
Kabanga



 

 

0 Kudos
Message 5 of 38
(5,265 Views)

It could really do the job, but there is a problem:
Is it possible to remove the  " [ ] "  and the " = " and replace it with colon  :   ?

Best regards
Kabanga

 

0 Kudos
Message 6 of 38
(5,256 Views)
Will all the sections be initialized with the same values when creating the file ? How do you then want to display/update one section (Data Replace) ? Is there a need to change the number of sections once the file has been created ?

It won't take to much time to make an example if you can go with the configuration type file. The file will be human readable and you can give it any extension (--> *.txt for example).
0 Kudos
Message 7 of 38
(5,257 Views)
It would be very easy to replace those both characters but then the file will no longer be readable by the configuration file VIs. I can suggest two solutions if this is really needed :
  1. Replace the characters before reading and after saving the file
  2. Save a copy of the file with the replaced characters

0 Kudos
Message 8 of 38
(5,249 Views)

All section sections have different initialization values (but some sections may have the same values. Remember, we have 128 sections)
There is no need to change the number of sections once the file is create.
"Data Replace" is just a parameter within a section and its values is "1"  or  "0".

 

0 Kudos
Message 9 of 38
(5,252 Views)
Please ignore my previous answer it was no more possible to edit it !

It would be very easy to replace/remove those both characters but then the file will no longer be readable by the configuration file VIs ([] and = are reserved characters). If those replacements are really essential (documentation...), you could save a modified copy
of the file. This file would not be used by your VI.

Obviously it is possible to solve your task without the configuration file VIs but it will be more work to do it this way.

0 Kudos
Message 10 of 38
(5,243 Views)