Count Disks Script

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
Foolio

Count Disks Script

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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.
Foolio

Post 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!
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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)
Ork
Posts: 44
Joined: 2003-01-03 23:52:51
Location: Castres, France

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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.
Guest

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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.
Ork
Posts: 44
Joined: 2003-01-03 23:52:51
Location: Castres, France

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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
Post Reply