<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">El 22/02/2017 a las 13:17, James
Richters escribió:<br>
<br>
</div>
<blockquote
cite="mid:076e01d28d05$9f803c60$de80b520$@productionautomation.net"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
tt
{mso-style-priority:99;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;
color:black;}
span.EmailStyle21
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle22
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle23
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">The
error I get is when trying to open the file to read it.
It’s something like read past end of file, because the
corrupted file is just one long line, once I read that, the
second read is past the end of file. I can do checking to
get the file length and avoid the error, but that doesn’t
solve the real issue, which is that the data that is
supposed to be in the file is just gone. </span></p>
</div>
</blockquote>
<br>
Just two lines of research ;-)<br>
<br>
A) While you are reading the file you call the procedure that writes
it.<br>
<br>
B) The is a bug, not in writing the part, but in the reading code:
Somewhere when you read the file, you don't close it, so the file
remains open. Usually it's not a big issue, you can open the file
several times, and when you close the program everything is closed.
But some times, when a parameter is changed you rewrite it while it
is still open and everything gets messed. So this two events must
happen, the program has executed the part of code that lets the file
open and next a parameter is changed.<br>
<br>
<blockquote
cite="mid:076e01d28d05$9f803c60$de80b520$@productionautomation.net"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"><o:p> </o:p></span></p>
<span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">The
thing is, even if windows forced a restart while my program
was running this file should have been closed at the time,
because if someone was standing there editing the variables,
they would see the restart notification and close the program
first, or be able to tell me they had a power failure. <o:p></o:p></span>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext">As
a temporary measure, I’m just writing out the file twice so
at least I have a backup, but I don’t see why the backup
would not be corrupted by this same issue, so that’s
probably pretty useless.</span></p>
</div>
</blockquote>
Yes, I think that's the way to go.<br>
<br>
1) Before writing, read it and if it's ok make a backup of the file<br>
2) Write the file.<br>
3) Read again what you have written to check whether it's ok. <br>
4) Make a second backup.<br>
<br>
That way, when you load parameters you have two backups to recover.
And maybe a clue of what's going wrong.<br>
Beside, I would add a timestamp inside the file.<br>
<br>
In addition, you could use flush and {$I-}<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Saludos
Santiago A.
</pre>
</body>
</html>