Loop takes a long time to do nothing

Why does the following take 7 minutes to run? (Warning! It will lock up Panorama while it is running and DO NOT touch another window while it is running!)

local pinfo,x,max
pinfo = initializedictionary(
    "SHEET",true(),
    "TITLE","Progress Test",
    "DONTBOTHER",0,
    "GUESSTIME",3)
max=250
for x,0,max
    progressalert pinfo,x,max
        local startTime
        startTime=now()
        loop
           nop
        until now()>startTime+1
endloop
progressalert pinfo,-1,max

I don’t know why your procedure takes so long, but I have had several procedures that may be interrupted and cause a failure if the user clicks on a different Panorama window. To handle this problem, I created a custom statement that I call PleaseWait. PleaseWait opens a dialog with whatever message you have added. Mouse clicks are ignored while the dialog is open but he procedure continues to run. You must add the PleaseWait form before running the statement. One important note: you must close the dialog with a closedialog statement or you will be stuck with it and you will have to Force Quit PanX. The format for the statement is PleaseWait “Message to display…”

fileglobal fgpwmessage
fgpwmessage=parameter(1)
let lvcurrentrec=info("windowrectangle")

 opendialog "PleaseWait","closeable","no","TitleBar","no"
    setwindowoptions "TOOLBAR","NO","SCROLLBARS","No"
    zoomwindowrectangle rectanglecenter(lvcurrentrec,rectanglesize(1,1, getformoption("","","MAXIMUMHEIGHT"),
    getformoption("","","MAXIMUMWIDTH")))
rtn

Robert, the reason is simple Math: The max number for the progressalert loop is 250. Then you set the nop phase to > 1 second. So the combined loops have to wait for 250 * 2 = 500 seconds.

LOL. Ok. I did not do the math. Before I put the loop in, it did nothing 250 times and took less than 2 seconds so I wanted to see the ProgressAlert for a bit longer and added the NOP for essentially 1 second although mathematically it is then 2 seconds.
I will instead do nothing more often, :slight_smile: or do it less often with 1 second loops.
Thanks for the time. And the math lesson.

You can get shorter delays using info(“tickcount”) or info(“milliseconds”) for the calculation of the StartTime variable. Then “+1” means +1/60 second respectively +1/1000 second. So with the following code the progress alert loop takes about 30 seconds only:

local pinfo,x,max
pinfo = initializedictionary(
    "SHEET",true(),
    "TITLE","Progress Test",
    "DONTBOTHER",0,
    "GUESSTIME",3)
max=250
for x,0,max
    progressalert pinfo,x,max
        local StartTime
        StartTime = info("tickcount")
        loop
            nop
        until info("tickcount") >= StartTime+6
endloop
progressalert pinfo,-1,max