PDA

View Full Version : How to cancel a Progress Bars screen running a for loop


AxemanMK
03-02-2007, 08:27 AM
Hi.

The very first screen in my setup is a progress bars screen.
Within the "On Start" tab of this screen, I have a for loop that does a CRC
comparison of every file on my CD.

EG : for every item in my table, compare CRC.

This way, I can at least prove that the CD-ROM drive can read every
file on my CD, which contains over 5500 files.

I have got everything working just fine, including incrementing the progress
bars, and plenty of error detection.

As this can take between 1 min to 5 mins depending on CD-ROM drive speed,
I want to give the user the ability to "Skip" this screen.

My Cancel button is labelled "&Skip", and the "On Cancel" tab has the following
code....

-----------------------------------------------------------------------
-- These actions are performed when the Cancel button is clicked.

local nResult = Dialog.Message("Confirm", "Are you sure that you skip the Validation Check ?", MB_YESNO, MB_ICONQUESTION);

if(nResult == IDYES)then

bCancelled = true;

-- Log fact that validation check has been skipped.
SetupData.WriteToLogFile("Notice The Validation Check has been skipped\r\n", true);

Screen.Jump("To my desired screen");

end
-----------------------------------------------------------------------

The problem is, I cannot figure out how to detect if the Cancel button has
been clicked while my for loop is running.

I tried nesting the following as the first set of code in the for loop....

-------------------------------------
if bCancelled == true then

break;

else

-- do the rest of my actions..

end
-------------------------------------

But this does not work !!

When I click the Cancel / Skip button, it appears that the for loop is
running so tight that the button never actually gets depressed and
the for loop will not quit.

Any ideas ?

jassing
03-03-2007, 10:49 PM
even more interesting; I did this in my start event:

local nBigNumber = 1000000;
DlgProgressBar.SetRange(CTRL_PROGRESS_BAR_01, 0, nBigNumber);

local x=0;
for x=1,nBigNumber do
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01, x);
end

and it scans but almost right away -- the progres bar jumps to "100%"
cancel button isn't visible. (but it's set to be visible)

I used StatusDlg to do what you're doing -- while not as "elegant" as using a screen, it will work as you want.

-- Setup parameters for scan
local nBigNumber = 1000000;
local bCancelled = false;
local x=0;

-- Display pgoress bar
StatusDlg.Show(0, false);
StatusDlg.ShowCancelButton(true,"Skip");
StatusDlg.SetMeterRange(0, nBigNumber);

-- Do the scan
for x=1,nBigNumber do
StatusDlg.SetMessage("X is "..x);
StatusDlg.SetMeterPos(x);
bCancelled = StatusDlg.IsCancelled();
if bCancelled then
break;
end
end

-- remove the dialog
StatusDlg.Hide();

-- Show that we sensed correctly what happened
if bCancelled then
Dialog.Message("Results","User skipped the scan");
else
Dialog.Message("Results","User did not cancel");
end

AxemanMK
03-04-2007, 09:48 AM
Hi Jassing. Thanks for the responce.

Yes, I agree. Maybe the only way to achieve this is to use status dialogue,
which is a shame as it isn't as gracefull.

I do have a number of Progress Bars screens that use the File.Copy action, although the copy action is not run through a for loop. Because the File.Copy action uses a function callback, it correctly senses the fact that the cancel button has been clicked.

This made me think that maybe trying to create a fuction might achieve what I want, but I cant think of how to call the function whilst locked within the for loop.

As usual, plenty of work to be done !!........ lol