Page 1 of 1

Count Disks Script

Posted: 2002-12-25 00:50:45
by Foolio
I was trying to write a script which would count up the total number of disks from fieldDisks. This is the first script I've attempted and am having some trouble figuring out how to have the script do something (like a ShowMessage) only after it has traversed the entire movie list. I can have the script (code below) pop-up a message at each movie and display the current total, but that's a bit of a pain with the number of movies I've got here. Any help here would be greatly appreciated. Thanks.

--Foolio

Code: Select all

// SCRIPTING
// Counts total number of disks
program CountDisks;
var
  dc: Integer;
begin
  dc := dc + StrToInt(GetField(fieldDisks), 0);
  ShowMessage(IntToStr(dc));
end.

Posted: 2002-12-25 09:58:42
by antp
For the moment it is not possible. It is one of the thing that I'll add, the possibility of executing a script one time for the whole list, instead of executing it for each movie.

Posted: 2002-12-25 19:46:31
by Foolio
I kinda had a hunch that was the case. ;) Oh well, I guess I'll just stick with my "Export to CSV, Load into Excel" method. Thanks!

Posted: 2002-12-25 19:58:58
by antp
A solution that may work:

Code: Select all

program CountDisks;
var
  Total: Integer;
  TempFile: TStringList;
begin
  TempFile := TStringList.Create;
  TempFile.LoadFromFile('c:\tempfile.txt');
  Total := StrToInt(TempFile.Text, 0);
  Total := Total + 1;
  TempFile.Text := IntToStr(Total);
  TempFile.SaveToFile('c:\tempfile.txt');
  TempFile.Free;
end.
Then you have the total in the file tempfile.txt (must be created before running the script I think)

Posted: 2003-01-03 23:58:51
by Ork
Why not just simply add a test on the number of your last movie?

Code: Select all

// SCRIPTING
// Counts total number of disks
program CountDisks;
var
  dc: Integer;
begin
  dc := dc + StrToInt(GetField(fieldDisks), 0);
  if GetField(fieldNumber)='650' then ShowMessage(IntToStr(dc));
end.

Posted: 2003-01-04 00:51:53
by antp
Because the "dc" variable will not be kept between each movie : for each movie it is like if the script program was closed and re-executed.

Posted: 2003-01-04 01:52:15
by Guest
I know you are the author of the program but the global variables keep their values between movies. I learned it when one of my scripts did not work because of a variable that I did not initialize explicitly.

Posted: 2003-01-04 09:56:12
by antp
Yes, but here as I said it is like if you exit the program (program Countdisk) and run it again for each movie.

Posted: 2003-01-04 23:23:31
by Ork
Ok, the script I wrote only works if you select all the movies before executing the script. Yours works if you execute it on each new movie you add, but be sure of not executing it twice on the same movie.

Posted: 2003-01-05 09:45:52
by antp
Mine works also if you select multiple movies. You just have to be sure than the file is empty before running it. If you had to run it for each movie it would be quite unuseful to make this as a script, it would easier to make the sum manually :D