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 Kabanga,

here's the same using "Format into string" (it could be simplified even more...).
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 21 of 38
(1,509 Views)
Hi GredW
that is really great !!!!!!!!
That is exactly what I was trying to do !
Thanks a lot.
Now I should complete the code so that I obtain a file
with the following structure (with all sections appended):
 
Begin Line1
       ....
      .......
End Line 1
 
Begin Line2
       ....
      .......
End Line2
 
Begin Line3
       ....
      .......
End Line3
 
--- etc  ----------- till
 
Begin Line128
       ....
      .......
End Line128
 
 
I hope I'll succed without disturbing you 🙂
 
Best regards
Kabanga
 
 
0 Kudos
Message 22 of 38
(1,500 Views)
Hi Kabanga,

as written before: put the vi from my last message into a (for) loop, wire i+1 to the "block number" control (set it as input in the subvi).

That's why I originally recommended to use an array of cluster...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 23 of 38
(1,483 Views)
Hi GredW, hi everyone
I used the VI you send me to create a sub-VI (please see the attached file).
I connected i+1 to the "block number" but know all the sections of the created file got the same number.

Also I wish to activate each section form the Front Panel. That means, I got 128 LEDs on the Front Panel. For every LED "on"
the corresponding sections should be written when the file is created.  The user should  also be able (from the Front Panel) to enter the parameters (Time, Time Type....) in these different sections.
What would you advise me to do to achieve my goal?
Thank you very much for any help

Note: 1)- The file created will be used by another application.
         2)-  "Setup" and "Data" are paths that are not used by LV.  We are just using LV to create and save these path in the created file so that another application use them.


Best regards
Kabanga

Download All
0 Kudos
Message 24 of 38
(1,459 Views)
Hi Kabanga,

my name is Gerd, not GredSmiley Wink

To achieve your goal you should use only one for loop, in the main vi OR in the sub vi. I changed the subvi to work without the loop...

Again:
To achieve all other goals you should put all your controls into a cluster (greatly cleans up the block diagram). Make an array of clusters to allow input of several 'blocks'. It's not very user friendly to present 128 boolean switches nor very easy to wire in the block diagram. Make an array, that's what it is good for!


Message Edited by GerdW on 02-03-2008 08:49 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 25 of 38
(1,451 Views)
Hi Gerd,
I'm sorry for the typo!!!  Smiley Wink
Thanks for your help. I'll implement the VI and tipps you gave me and will let you know the outcome later.

Best regards
Kabanga
0 Kudos
Message 26 of 38
(1,438 Views)

Hi Gerd,

Here how does my user interface look like.
I created cluters of boolens, then build an array of cluster as you said. Finally I put a  "Boolean Array To Number" VI  which I connect to the "block number".
After execution the file contain only one section numbered "0". What is happened? why doesn't it work?
Thanks for your help!

Best regards
Kabanga

 

0 Kudos
Message 27 of 38
(1,424 Views)
Hi Kabanga,

it seems I should have explained this in more detail...
You don't need 128 booleans in the user interface - it will just irritate the user!

See attachment:
I put all your data elements into a cluster. (I also simplified the data saving/formatting - it's a fixed format, so you don't need to check for changed data labels!)
In the user interface I made an array of those clusters and initialized it with 128 elements. And the saving should work too.

You have to make a more "user safe" input by checking data ranges, limiting array elements, etc. (see comments).
I would present just the cluster to the user with a block number. When the user clicks an "ok" button this cluster is replaced in the array...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 28 of 38
(1,417 Views)
Hi Gerd,
I modified a little bit the VI you sent me last  time.
 
Know, to create the txt file the user should:
1)- give the block number
2)-change the parameters (Time, Time Type..)
3)-hit "save" to save the changes
4).repeat  1) to 3) (every new block is appended to the file)
 
It's working but I have some problems and questions and hope you'll help me. It's a pity that I cannot rate the answers. I'd rate them "excellent" because I'm very satisfied !!!!
 
A)-After I added the While Loop, my VI is freezing when I start it (but apparently it's working in background, because even if it's frozen, when I change the block number, parameters and hit "save" the block is appended!!!). How can I solve that problem?
 
B)- I'd like to create a header "Batch File: 2.0" to the file but I couldn't. I've tried to concatenate the string "Batch File: 2.0" with the output of the VI "Format into String" but it's not working.
 
C)-I'd like to view the created file by hiting "Load File". How can implement that?
 
Best regards
Kabanga
 
0 Kudos
Message 29 of 38
(1,379 Views)
Hi Kabanga,

A) you included a stop-button in the while loop. But the front panel of the vi doesn't open when the vi gets called - you never have a chance to stop this vi! Hence it "freezes"! Either make the front panel op (vi properties -> window appearance) or don't use a while loop here. I would prefer the second option as this vi only serves the purpose of saving data.

B) In the attachment I added "Batch File: 2.0" in the format string - it will appear before every data block... You can also write it once (in the main vi) when you create the file...

C) I would make a separate vi for laoding the file. No need to include all functions in one vi...

D) As I said long before: reorganize this file handling:
- load an existing batch file at start
- parse all blocks into an array of cluster
- allow editing by the user for each cluster
- save the whole array into a file at the end
This will save you a lot of file operations (open/read/write/close). You can hold all values in memory, it's just ~10kB of data...
Best regards,
GerdW


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