SRL Archive - General

Can you load data from a file?


Terror Factor

2010-02-03 16:07:32

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
SendKeys(Array[i]);
I should be able to get a specific line from a textfile or an excel, something like this:
SendKeys(LineOfTextFile[i]);
or
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:(

Naum

2010-02-03 16:10:01

Read about INI files, that must be what you're looking for :).

EDIT: http://www.villavu.com/forum/showthread.php?t=27994&highlight=loading
http://www.villavu.com/forum/showthread.php?t=28301&highlight=loading

Frement

2010-02-03 16:10:26

From: Terror Factor
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
SendKeys(Array[i]);
I should be able to get a specific line from a textfile or an excel, something like this:
SendKeys(LineOfTextFile[i]);
or
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:
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
}

Terror Factor

2010-02-03 16:24:09

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 :p What are the parameters for in this command:
ReadFileString( F, S, FileSize( F ) );
?

Terror Factor

2010-02-03 16:51:40

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

Dynamite

2010-02-03 17:07:25

IntToStr

:)

Terror Factor

2010-02-03 17:08:58

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