Results 1 to 4 of 4

Thread: Adding text to a file...

  1. #1
    Join Date
    Oct 2006
    Posts
    1,211
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Adding text to a file...

    Ok i'm having some issues >.<
    I want to ADD text to a file not just replace the whole thing. For some reason it doesnt work and it just replaces it
    SCAR Code:
    program New;

    procedure AddToDebug(S: String);
    var
      FileNum, L: integer;
      P: String;
      begin
      AddToReport(S);
      FileNum := RewriteFile(ScriptPath+'[TEST].txt', True);
      if( FileNum < 0 )then
        AddToReport('Couldn''t save report!');
      L := FileSize(FileNum);
      Writeln('File Length: '+inttostr(L));
      ReadFileString(FileNum, P, L);
      Writeln(P);
      WriteFileString(FileNum, Trim(P)+S);
      CloseFile(FileNum);
    end;

    begin
      AddToDebug('Hello');
    end.
    Extinct.

    Formally known as Drags111.

  2. #2
    Join Date
    Feb 2009
    Posts
    1,447
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I think the reason why it rewrites is because...
    SCAR Code:
    FileNum := RewriteFile(ScriptPath+'[TEST].txt', true);
    Its telling to rewrite the file...

  3. #3
    Join Date
    Oct 2006
    Location
    C:\Program Files\SCAR 2.03
    Posts
    1,194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    program New;

    procedure AddToDebug(S: String);
    var
      FileNum, L: integer;
      P: String;
      begin
      AddToReport(S);
      //FileNum := RewriteFile(ScriptPath+'[TEST].txt', True);
      Filenum:= OpenFile(ScriptPath+'[TEST].txt', true);
      if( FileNum < 0 )then
        AddToReport('Couldn''t save report!');
      L := FileSize(FileNum);
      Writeln('File Length: '+inttostr(L));
      ReadFileString(FileNum, P, L);
      Writeln(P);
      //
      CloseFile(Filenum);
      FileNum:= RewriteFile(ScriptPath+'[TEST].txt', True);
      WriteFileString(FileNum, Trim(P)+S);
      CloseFile(FileNum);
    end;

    begin
      AddToDebug('Hello');
    end.

    The reason is because you never opened the file to "read" it, you only opened it to edit it therefor it could never "read" from the file because it wasn't supposed to.

    You had the right idea, you just weren't familiar enough with the functions. Good luck and if you need any other help with scripting let me know =).
    [FONT="Garamond"][SIZE="3"]
    Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.
    [/SIZE][/FONT][URL="http://www.villavu.com/forum/forumdisplay.php?f=125"][IMG]http://i40.tinypic.com/r1lzdv.jpg[/IMG][/URL]

  4. #4
    Join Date
    Jan 2007
    Location
    BC, Canada
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thank you Ed. just what i have been looking for. very much appreciated

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 10-11-2008, 03:48 AM
  2. How To Read The Exact Text From A File?
    By Maninblack144 in forum OSR Help
    Replies: 5
    Last Post: 05-13-2008, 05:51 PM
  3. Writing to a text file
    By JNCR in forum OSR Help
    Replies: 2
    Last Post: 10-20-2007, 02:33 PM
  4. Getting Text File from Web?
    By MacroHawk in forum OSR Help
    Replies: 3
    Last Post: 05-12-2007, 03:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •