Results 1 to 11 of 11

Thread: help me please :)

  1. #1
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default help me please :)

    right now lets start of by saying hi
    i havent been here for a long time but i needed something done and i have become stuck
    i have not opened scar for a good 4-5 months so i cannot remember if this is possible and if so how you do it but here is my question

    i have a array of strings
    textblah[0]
    textblah[1]
    textblah[2]
    textblah[3]

    this is a lot of text so it will probably go to a few billion
    i want to know if i can use one command or a loop to save all of them to a text file
    or save it to a text file then replace the var then save that on a new line on the text file then replace the var etc etc

    any help is greatly appriciated

    ~shut

  2. #2
    Join Date
    Nov 2007
    Location
    46696E6C616E64
    Posts
    3,069
    Mentioned
    44 Post(s)
    Quoted
    302 Post(s)

    Default

    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 GetFolders(Path: string): TStringArray;
    Returns the folders 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. 
    
    function GetFileSize(FileName: string): Int64;
    Returns the size of a file without opening it.
    Mainly you need only:
    Code:
    function RewriteFile(Path: string; Shared: Boolean): Integer;
    
    function WriteFileString(FileNum: Integer; s: string): Boolean; 
    
    procedure CloseFile(FileNum: Integer);
    There used to be something meaningful here.

  3. #3
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    well i have this and it gave me a file access error
    SCAR Code:
    program New;

    var
      test:string;
      i, thefile:integer;

    begin
      thefile:= OpenFile('C:\testing.txt', true);
      for i:=0 to 10 do
      begin
        test:= inttostr(i);
        WriteFileString(thefile, test);
      end;
      CloseFile(thefile);
    end.
    ao i thought someone else could make me one

    could it be because in not using RewriteFile?

    ~shut

    EDIT: i closed scar and reopened it and the access error has gone
    but nothing gets written to the file
    Last edited by Shuttleu; 04-02-2010 at 10:31 PM.

  4. #4
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Use RewriteFile
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    And if you want to append, first use OpenFile and read the text and prepend it to the variable you are writing to the file.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    good its writing now
    now one problem... it doesnt write them on new lines
    i have this
    SCAR Code:
    program New;

    var
      test:string;
      i, thefile:integer;

    begin
      thefile:= RewriteFile('C:\testing.txt', false);
      for i:=0 to 10 do
      begin
        test:= inttostr(i)+chr(32);
        WriteFileString(thefile, test);
      end;
      CloseFile(thefile);
    end.
    the chr(32) was my attempt to make it put it on a new line, but it didnt work. it only made it make spaces

    ~shut

  7. #7
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Use #10+#13

    So:
    SCAR Code:
    test:= inttostr(i)+#10+#13;

    That should work

  8. #8
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    still nope...
    owell i suppose scar will just have a lot of stuff in the debug window

    ~shut

  9. #9
    Join Date
    May 2007
    Location
    Ohio
    Posts
    2,296
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    try this..
    SCAR Code:
    program New;

    var
      Restore: string;
      i, TheFile, h: Integer;
      WriteToFileS: TStringArray;

    begin
      WriteToFileS := [
      'Hey',
      'you',
      'look',
      'it',
      'works!'
      ];

      if (FileExists('C:\Testing.txt')) then
      begin
        TheFile := OpenFile('C:\Testing.txt', False);
        ReadFileString(TheFile, Restore, FileSize(TheFile));
        CloseFile(TheFile);
      end;
      TheFile := RewriteFile('C:\Testing.txt', False);
      WriteFileString(TheFile, Restore);
      h := High(WriteToFileS);
      for i := 0 to h do
        WriteFileString(TheFile, WriteToFileS[i] + Chr(13));
      CloseFile(TheFile);
    end.

  10. #10
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    lolwut doesn't work, Timer.

  11. #11
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Code:
    var
    s, ss : string;
    FileNum, h, i : integer;
    Ex : TStringArray;
    begin
    s := 'Write\nThis\nTo\nFile';
    Ex := Explode('\n', s);
    ClearDebug;
    h := high(Ex);
    for i := 0 to h do
    Writeln(Ex[i]);
    FileNum := RewriteFile('C:\wat.txt', False);
    WriteFileString(FileNum, GetDebugText);
    end.

    To use your array of strings instead of exploding it just use your array.
    If you want to use the explode, implode the array with \n as separator.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

Thread Information

Users Browsing this Thread

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

Posting Permissions

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