09-03-2025 11:10 AM
Hi all, I'm trying to create a program to save data in a txt file, but why is it that after the program is aborted, and we use the same file to save the data, the previous data is overwritten and lost? Is there a way to overcome this? Thanks all.
09-03-2025 11:24 AM
Here's a couple suggestions:
1> When you open the file set it to Open or Create.
2> Set the file position to End before you write to the file.
09-03-2025 11:50 AM - edited 09-03-2025 11:50 AM
@RTSLVU wrote:2> Set the file position to End before you write to the file.
Is it sufficient to set the file position (to "end") right after opening, and before the loop. Inside the loop it will append automatically.
09-03-2025 01:10 PM
@altenbach wrote:
@RTSLVU wrote:2> Set the file position to End before you write to the file.
Is it sufficient to set the file position (to "end") right after opening, and before the loop. Inside the loop it will append automatically.
You are right, setting the position every time before I write is just a habit I fell into. I can't remember exactly why, probably from patching some really bad code I wrote in the past.
09-05-2025 11:03 AM
How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.
09-05-2025 11:13 AM - edited 09-05-2025 11:17 AM
@sinclair15 wrote:
How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.
Yes there is a way..
This can be done programmatically, there's a "Create File with Incrementing Suffix" that can auto generate file names with 001, 002, 003 automatically added to the file name.
Now we haven't seen your actual program so I am just going to say that if you are using One Big Loop (OBL) as your program architecture you need to stop and use a proper architecture like a simple state machine. Then doing things like opening and closing new files when necessary or at user request is far easier to program
09-06-2025 09:03 AM
@sinclair15 wrote:
How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.
Words are insufficient to describe a program architecture. Once you show us your new code, we can quickly tell what you are doing wrong.
09-06-2025 10:15 AM
like this?
09-06-2025 10:50 AM - edited 09-06-2025 10:59 AM
@sinclair15 wrote:
like this?
Your code is permanently locked in the inner loop and the path control will only get read once at the start of the program. When you stop the inner loop, both loops will terminate. Think dataflow!
09-06-2025 11:28 AM
ignore about the loops, i just want to be able to control the path and change files while the program is running, how do i do that?