Results 1 to 3 of 3

Thread: Writing to a text file

  1. #1
    Join Date
    Sep 2007
    Location
    Behind You
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Writing to a text file

    For a script that I am making, it writes to a text file.

    I cannot seem to get it to skip a line or do the equivalent or someone pressing enter after typing a line.

    I have read somewhere that the decimal for enter is 13 but it does nothing.

    All help would be greatly appreciated.

    ~JNCR
    The[Cheese] really puts it perfectly:

    Reflection is win

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Chr(13) is new line.
    SCAR Code:
    File functions

    function OpenFile(Path: string; Shared: Boolean): Integer;
    Opens file for reading and returns file number if successful or negative number if failed. If shared = true then attempts to open files used by other applications as read-only.

    function RewriteFile(Path: string; Shared: Boolean): Integer;
    Opens file for writing and truncates it. Returns file number if successful or negative number if error.

    procedure CloseFile(FileNum: Integer);
    Closes file specified by FileNum.

    function EndOfFile(FileNum: Integer): Boolean;
    Returns true if end of file specified by FileNum reached.

    function FileSize(FileNum: Integer): LongInt;
    Returns file size in bytes.

    function WriteFileByte(FileNum: Integer; b: Byte): Boolean;
    Writes a single byte to file.

    function WriteFileInt(FileNum: Integer; i: Integer): Boolean;
    Writes a single integer to file.

    function WriteFileString(FileNum: Integer; s: string): Boolean;
    Writes a string to file.

    function ReadFileByte(FileNum: Integer; var b: Byte): Boolean;
    Reads a single byte from file.

    function ReadFileInt(FileNum: Integer; var i: Integer): Boolean;
    Reads a single integer from file.

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

    procedure WriteINI(Section, KeyName, NewString, FileName: string);
    Writes data to an ini-structured file.
    Structure:
    [Section]
    KeyName=NewString

    function ReadINI(Section, KeyName, FileName: string): string;
    Reads data from an ini-structured file.
    Structure:
    [Section]
    KeyName=SomeString

    procedure DeleteINI(Section, KeyName, FileName: string);
    Deletes a KeyName from an INI file and if you pass an empty string as KeyName it will delete then entire Section.

    function DirectoryExists(Directory: string): Boolean;
    Returns true if the directory exists.

    function FileExists(FileName: string): Boolean;
    Returns true if the file exists.

    function ExtractFileName(FileName: string): string;
    Returns the name of a file from a string.
    Example:
    C:\somefolder\somefile.ext => somefile.ext

    function ExtractFilePath(FileName: string): string;
    Returns the filepath from a string.
    Example:
    C:\somefolder\somefile.ext => C:\somefolder\

    function ExtractFileExt(FileName: string): string;
    Returns the file extension from a string.
    Example:
    C:\somefolder\somefile.ext => .ext

    function ExtractFileDrive(FileName: string): string;
    Returns the file drive from a string.
    Example:
    C:\somefolder\somefile.ext => C:

    function GetFiles(Path, Ext: string): TStringArray;
    Returns the files in a directory.

    function SaveToFile(Sender: TObject; FileName: string): Boolean;
    Saves the content of certain objects:
    TStrings, TStringList, TBitmap, TImage, TPicture, TMemo, TListBox, TComboBox, TRichEdit, TCheckListBox, TGraphic
    Returns True if the saving was succesful.

    function LoadFromFile(Sender: TObject; FileName: string): Boolean;
    Loads the content of certain objects:
    TStrings, TStringList, TBitmap, TImage, TPicture, TMemo, TListBox, TComboBox, TRichEdit, TCheckListBox, TGraphic
    Returns True if the loading was succesful.

    function MD5FromFile(Filepath: string): string;
    Returns the MD5 hash value of a file.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Sep 2007
    Location
    Behind You
    Posts
    72
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah I tried Chr(13) but it did nothing. Am I using it wrong?

    Here is what I have so far:
    SCAR Code:
    WriteFileString(RewriteFile('C:\Test.txt', False), '***** '  + Chr(13) + '*****' + Chr(13) + '*****');

    (The *'s are used because I have not released it yet.)

    When the code is run it does not make a new line as I had hoped.

    ~JNCR

    [Edit] Decided to use ini's instead. Much easier.[Edit]
    The[Cheese] really puts it perfectly:

    Reflection is win

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. Reading and Writing to file
    By king vash in forum OSR Help
    Replies: 2
    Last Post: 01-22-2008, 03:20 PM
  3. Replies: 2
    Last Post: 09-18-2007, 12:49 AM
  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
  •