01-28-2019 03:32 PM
Hi there,
I have a problem where I am continually rewriting data to a line in a text file through a series of questions. The user has the ability to move back and forth through a sequence of steps and the line of output is written after each step is finished (this is done as a full safe in case they stop the program before completing all of the steps). Occasionally the final line of data ends up being shorter than one of the previous times the data was written to that line resulting in junk at the end of the line. I am wondering if there is a way to easily erase the line written previously before the next line is written. This line is being appended to a file containing other lines so I can't simply overwrite the whole file - I have an initial offset value that is the start of the new line.
Hopefully this makes sense!
Thank-you for any help you can offer.
Solved! Go to Solution.
01-28-2019 03:51 PM
Without seeing code, it is hard to tell, but it seems you use a fixed size line for each entry. Just pad the string with the correct number of spaces before writing.
01-28-2019 04:25 PM
I had thought about this - but I am using array to spreadsheet string before writing so I wasn't sure how to do this and I thought the other method might be easier. I will play around with padding before the return and see if I can figure it out!
Thank-you!
01-28-2019 04:39 PM
After "array to spreadsheet string", you have a plain string that you could e.g. pad/truncate to a fixed length as follows.
01-28-2019 04:41 PM
Personally, I would just keep all lines in memory and rewrite the file after each change.
01-29-2019 03:10 PM
Thank-you! This worked really well and solved my problem.
Thanks for your time - I appreciate it!