Page 1 of 1

Having trouble writing to a text file

PostPosted: June 28th, 2007, 4:28 am
by Wardlow
Here a function I have that writes to a next file. This function is called many times because it is in a while loop. NumFiles, gets incremented, 0, 1, 2, 3, 4. The first time the function is called I want to rewrite the file, however the 2nd time I call the function I don't want it to rewrite the file... I want to keep on adding to the file.

What I have down here results in an error. Anyone know what I should do?

Thanks

Code: Select all
function WriteFile
begin
        if NumFiles = 0 then
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Rewrite(SendFile);
        end
        else
          AssignFileSendFile, 'c:\ProgramResults\3ParametersData.txt');


writeln(SendFile, 'HELLOMOM');

closefile(Sendfile);
end;


PostPosted: June 28th, 2007, 5:32 am
by HPW
Try this (Untested):
Code: Select all
function WriteFile
begin
        if NumFiles = 0 then
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Rewrite(SendFile);
        end
        else
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Append(SendFile);
        end;
writeln(SendFile, 'HELLOMOM');
closefile(Sendfile);
end;

PostPosted: June 28th, 2007, 4:16 pm
by Wardlow
thank for perfect thank you very much