Results 1 to 3 of 3

Thread: Reading and Writing to file

  1. #1
    Join Date
    Feb 2007
    Posts
    419
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Reading and Writing to file

    I'm want to write a bunch of data (6 integers and 1 string) to the end of a text file. It would be prefferable if they were all on the same line. I can't figure out how to do this.
    I know how to write my data to a file
    Code:
        filenum:= RewriteFile(filepath,false);
        WriteFilestring(filenum,combo);
        WriteFileInt(filenum,face1);
        WriteFileInt(filenum,face2);
        WriteFileInt(filenum,face3);
        WriteFileInt(filenum,face4);
        WriteFileInt(filenum,face5);
        WriteFileInt(filenum,face6);
        CloseFile(filenum);
    and i know how to open the old file and get the size of it.
    Code:
        oldnum := OpenFile('C:\itegrate\programming\Scar\Scripts\cube\anal\cubelevel' + inttostr(cubelevel) + '.txt', false)
        size:= filesize(oldnum);
        CloseFile(oldnum);
    but if i use the ReadFileString command it wants a integer as filesize and the filesize command returns a extended. otherwise i would use this code
    Code:
        oldnum := OpenFile('C:\itegrate\programming\Scar\Scripts\cube\anal\cubelevel' + inttostr(cubelevel) + '.txt', false)
        size:= filesize(oldnum);
        ReadFileString(oldnum, oldinfo,size);
        CloseFile(oldnum);
    ^doesn't work

  2. #2
    Join Date
    Aug 2007
    Posts
    429
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    For the first part I would just make it a string and put them all together.
    Like so:
    SCAR Code:
    filenum:= RewriteFile(filepath,false);
        WriteFileString(filenum,combo);
        WriteFileString(filenum, IntToStr(face1) + IntToStr(face2) + IntToStr(face3) + IntToStr(face4) +  IntToStr(face5) + IntToStr(face6));
        CloseFile(filenum);
      //and you can add spaces in between the numbers or whatever


    And actually FileSize returns a LongInt not an extended.
    So it'll still work

  3. #3
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    King,

    function ReadFileString(FileNum: Integer; var s: string; Length: Integer): Boolean;
    Reads Length number of bytes from file into string s.
    FileNum as ReWriteFile(...)

    s the thing it returns what it read

    length - how many bytes/characters/ whatever to read.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. File Writing
    By Metagen in forum OSR Help
    Replies: 7
    Last Post: 08-04-2008, 05:47 PM
  2. INI writing/reading/deleteing
    By Negaal in forum OSR Advanced Scripting Tutorials
    Replies: 2
    Last Post: 03-31-2008, 08:12 PM
  3. C++: Writing and reading files
    By Repentinus in forum C/C++ Help and Tutorials
    Replies: 3
    Last Post: 11-11-2007, 04:55 PM
  4. Writing to a text file
    By JNCR in forum OSR Help
    Replies: 2
    Last Post: 10-20-2007, 02:33 PM

Posting Permissions

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