Results 1 to 7 of 7

Thread: Can you load data from a file?

  1. #1
    Join Date
    Dec 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Can you load data from a file?

    Hi,

    I'm currently having a problem with a script I wrote. It fills in a form and submits it to a website, but the info it submits, is in 4 seperate arrays. All 4 arrays have about 5000 entries. This is too much for my old pc to handle well. My dual core takes about 60s to compile the script, and my pentium 4 can't even compile it most of the time, scar just crashes.

    Now, I wondered if I could store the info in a textfile or an excel, and let scar load that file, and get the info from there. Is it possible to load info from a file, AND address it?
    I now use something like
    Code:
    SendKeys(Array[i]);
    I should be able to get a specific line from a textfile or an excel, something like this:
    Code:
    SendKeys(LineOfTextFile[i]);
    or
    Code:
    SendKeys(Row[i],Column[y]);
    Can I do something like that, and how? And if not, what other solution could I use? Copy-pasting from excel results quickly in errors, I'm afraid

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

    Default

    Last edited by Naum; 02-03-2010 at 09:12 PM.

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

    Default

    Quote Originally Posted by Terror Factor View Post
    Hi,

    I'm currently having a problem with a script I wrote. It fills in a form and submits it to a website, but the info it submits, is in 4 seperate arrays. All 4 arrays have about 5000 entries. This is too much for my old pc to handle well. My dual core takes about 60s to compile the script, and my pentium 4 can't even compile it most of the time, scar just crashes.

    Now, I wondered if I could store the info in a textfile or an excel, and let scar load that file, and get the info from there. Is it possible to load info from a file, AND address it?
    I now use something like
    Code:
    SendKeys(Array[i]);
    I should be able to get a specific line from a textfile or an excel, something like this:
    Code:
    SendKeys(LineOfTextFile[i]);
    or
    Code:
    SendKeys(Row[i],Column[y]);
    Can I do something like that, and how? And if not, what other solution could I use? Copy-pasting from excel results quickly in errors, I'm afraid
    ReadINI() and WriteINI() should work just fine.

    E: This is what i did:
    SCAR Code:
    program TheFile;

    function ReadTheFile( PathToFile: String; I: Integer ): String;
    var S: String;
        F: Integer;
        TheArray: Array of String;
    begin
      F := OpenFile( PathToFile, False );
      ReadFileString( F, S, FileSize( F ) );
      CloseFile( F );
      TheArray := Explode( ';', S );
      Result := TheArray[ I ];
    end;

    function WriteTheFile( PathToFile, NewString: String; I: Integer ): Boolean;
    var S, TheString: String;
        F, O: Integer;
        TheArray: Array of String;
    begin
      TheString := '';
      F := OpenFile( PathToFile, False );
      ReadFileString( F, S, FileSize( F ) );
      CloseFile( F );
      TheArray := Explode( ';', S );
      TheArray[ I ] := NewString;
      for O := 0 to GetArrayLength( TheArray ) - 1 do
      begin
        if not ( O = 0 ) then begin
          TheArray[ O ] := ';' + TheArray[ O ];
        end;
        TheString := TheString + TheArray[ O ];
      end;
      F := RewriteFile( PathToFile, False );
      WriteFileString( F, TheString );
      CloseFile( F );
      Result := True;
    end;

    begin
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'usernametest', 0 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 0 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'passwordtest', 1 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 1 ) );
    WriteTheFile( ScriptPath + 'test.txt', 'pintest', 2 );
    Writeln( ReadTheFile( ScriptPath + 'test.txt', 2 ) );
    end.

    {OUTPUT:
    Successfully compiled (25 ms)
    username
    password
    pin
    usernametest
    passwordtest
    pintest
    Successfully executed
    FILE:
    username;password;pin
    }
    Last edited by Frement; 02-03-2010 at 09:13 PM.
    There used to be something meaningful here.

  4. #4
    Join Date
    Dec 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks both, I'll start reading now!

    EDIT: the ini method will do the trick I think, and it's easy too.

    @Frement: your method looks nice too, but is quite a bit more complicated What are the parameters for in this command:
    Code:
    ReadFileString( F, S, FileSize( F ) );
    ?
    Last edited by Terror Factor; 02-03-2010 at 09:36 PM.

  5. #5
    Join Date
    Dec 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Small problem: how can I convert an int to a string, since the ReadIni only works with strings, and I can't use:
    Code:
    program Hallo;
    var i:Integer;
    begin
      i:=2;
      WriteINI('Writing section', i, 'test', ScriptPath+'\ini writing');
    end.

  6. #6
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    IntToStr


  7. #7
    Join Date
    Dec 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hehe, just found it too, but thanks! ^^

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
  •