Skip to main content

[archive] Progress window and Cancel button

  • July 10, 2009
  • 7 replies
  • 1 view

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)

7 replies

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
You should just have to do a "STOP THREAD WS-PROGRESS-HANDLE" after the grid has been completely filled.

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
You should just have to do a "STOP THREAD WS-PROGRESS-HANDLE" after the grid has been completely filled.

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
Well I'm sure that stops the thread, but by the time Grid is done loading the Thread has run it's course anyhow. The window still doesn't close. I have tried puting a wait for thread then performing the Acu-ProgWin-Exit routine and this works fine. but then I lose the ability for the user to click on the cancel button. lol

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
Are you displaying your window that you're wanting to destroy in the WS-PROGRESS-HANDLE thread?
If so, then stopping the thread should destroy your window.

When we print, we start a program in a separate thread that displays a window that will allow the user to cancel.
Here's basically what we do to start the thread:


    SET PRINTING-COMPLETE TO FALSE.
    SET PRINTING-CANCELLED TO FALSE.
    MOVE 0 TO CANCEL-THREAD-RETURN.
    CALL THREAD "UCANCLPG.COB" HANDLE CANCEL-THREAD
        RETURNING INTO CANCEL-THREAD-RETURN.


Then, as we're printing, we routinely do the following test:


    do some printing...
    PERFORM CHECK-CANCELLED-PRINT.
    IF PRINTING-CANCELLED
       do something to exit gracefully...
       
CHECK-CANCELLED-PRINT SECTION.
    IF (CANCEL-THREAD-RETURN = 99)
       SET PRINTING-CANCELLED TO TRUE.
CHECK-CANCELLED-PRINT-EXIT.
    EXIT.


If the cancel button is pressed in the CANCEL-THREAD, it returns 99 to the primary thread.
Then once we're done printing, we do something like this:


    the user never pressed the cancel button in the CANCEL-THREAD...
    SET PRINTING-COMPLETE TO TRUE.
    do some other cleanup...
    IF PRINTING-COMPLETE
       STOP THREAD CANCEL-THREAD.


If the user had already pressed the cancel button in the CANCEL-THREAD, that program would have destroyed the cancel window and PRINTING-COMPLETE would never get set to true. If the user didn't cancel, PRINTING-COMPLETE gets set to true and the STOP THREAD statement that gets performed will close the CANCEL-THREAD and destroy its window.

I hope this helps.

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
Thanks for your insights into this, I had initially coded it the way you describe in your example but it was always going off into LA LA Land after I stopped the thread. Anyhow I tried putting back to the way you describe here,a nd still same thing was happening, even when I stepped thru the code I could see it just lost it's place after I had stopped the thread and went off into no man's land.

Eventually I figured out I had the BIND-TO-THREAD set to TRUE. Setting this to FALSE solved all my problems...

I dunno what the difference between BIND-TO-THREAD and LINK-TO-THREAD are, but LINK-TO-THREAD = TRUE and BIND-TO-THREAD = FALSE is the right combination.

Big Thanks for your samples and help :-)

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
Thanks for your insights into this, I had initially coded it the way you describe in your example but it was always going off into LA LA Land after I stopped the thread. Anyhow I tried putting back to the way you describe here,a nd still same thing was happening, even when I stepped thru the code I could see it just lost it's place after I had stopped the thread and went off into no man's land.

Eventually I figured out I had the BIND-TO-THREAD set to TRUE. Setting this to FALSE solved all my problems...

I dunno what the difference between BIND-TO-THREAD and LINK-TO-THREAD are, but LINK-TO-THREAD = TRUE and BIND-TO-THREAD = FALSE is the right combination.

Big Thanks for your samples and help :-)

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also :-)
I had forgotten about the BIND TO THREAD and LINK TO THREAD.
What's really interesting is that I just checked our cancel program and it just uses BIND TO THREAD.
Glad it all worked out for you. :)