Mid-Michigan Computer Consultants, Inc.
509 Center
Bay City, Michigan

Sales (989) 892-9242             Support (989) 686-8860

ANSI Standard PL/B Language
PL/B WINDOWS offers a "PERCENT PROGRESS BAR" object such at that found in most Windows applications.

The PL/B forms designer provides for direct creation of a progress bar. Simply click on the icon and then stretch the bar to the size that you want to use.
The progress bar is very simple to use. You simply use a SETPROP instruction naming the progress object and giving the percentage to be displayed. You can do this in a loop and continuously display the progress.
SM_COUNT       FORM 6.2
SM_MAX         FORM 6.2

        CALC    PERCENT_WORK = (SM_COUNT / SM_MAX) * 100  ;decimal work
        MOVE    PERCENT_WORK,PERCENT                      ;fixed
        SETITEM FR401000ProgressBar001,0,PERCENT
An alternate method for setting the percent was introduced in the Sumbelt manual in mid-Sept 1998's 8.2L patch.

The new property is VALUE={dnuminvar}. This can be used in a CREATE / SETPROP / GETPROP statement for a prgress bar. The {dnuminvar} value can be from 0 to 100. Values over 100 are set to 100.

This adds more methods for retrieveing and changing the percent value. Previously we only had SETITEM and GETITEM.
In actual operation, of course, you have to do a bit more than this. The example we'll use calls for an on screen box which contains a progress bar and a CANCEL button.

In this particular application, we're printing a report. Using the screen designer we built a form which had a few radio buttons to specify report options and we had a RUN button and a CANCEL button.

A progress box was also built on the screen with the forms designer. In this case the VISIBLE property was set to FALSE for each item so that none of it shows up at run time. The box consisted of:
a CANCEL button
a PROGRESS bar object
a GROUP BOX surrounding those two.
The purpose of the GROUP BOX was just to put a nice visual box around the progress bar and the CANCEL button.

(Note that the designer has a problem in this case. I laid in the button and progress bar then dragged the group box around them. But once that was done I could NOT click on the button or progress bar... I'd always get the group box instead. I learned that by exiting the designer then coming in again and reloading the form it worked OK.)

In operations, the user marks the radio buttons for the report options he desires then he clicks the RUN button.

At that time the program will DISABLE each of the radio buttons and the RUN and EXIT buttons. Then it will set the VISIBLE property to ON for the three objects in the progress box to make them show up on the screen.
....... Start by deactivating the option objects on the screen
....... since we're done with them now:
         DEACTIVATE   FR401000Radio001      ;Main option objects
         DEACTIVATE   FR401000Radio002
         DEACTIVATE   FR401000Button001     ;Run button
         DEACTIVATE   FR401000Button004     ;Exit button
....... Now make the progress box items visible:
         SETPROP      FR401000GroupBox001,   VISIBLE=1
         SETPROP      FR401000ProgressBar001,VISIBLE=1
         SETPROP      FR401000Button002,     VISIBLE=1
         EVENTREG     FR401000Button002,     $CLICK, CANCEL_CLICK
The above gets the screen ready for the processing part of the program. The setup items are disabled and the progress box with the CANCEL button and the PROGRESS bar are all visible

The next step is to pre-scan the file to see how many records we're going to process. This will allow us to calculate a percent of completion.

This pre-scan pass may not be the best thing to do if you have a huge file to process. But it may also be the only way to figure out how many records there are to be printed. You may have to decide based on the anticipated volume.
         MOVE      ZERO,SM_MAX              ;this will be total records
         MOVE      " ",SMRECKEY             ;prime the file
         CALL      SMIOREAD                 ;standard I/O READ routine
           CALL    SMIORKS                  ;standare I/O READKS routine
           MATCH   NO,SMNIF                 ;check for EOF
           BREAK IF NOT EQUAL               ;break out if true
           ADD     ONE,SM_MAX               ;count the record
         REPEAT                             ;continue until done
We're now ready to actually process the file. This is fairly straight forward but there is one trick.

That trick deals with the cancel button. Since we're in a processing loop we don't have a WAITEVENT running. What that means is that the user can click on the button all day and the program will never see it happen.

To solve the problem, we insert an EVENTCHEK into the loop. That causes the runtime to check the windows event table and do any required event processing.

Note that in the designer we put some code with the CANCEL button's CLICK event. The only thing the code does is:
         MOVE      "STOP" TO ACTION_TEXT
That is enough to let us know that the button was clicked. (ACTION_TEXT is a 30 byte string that we put in all of our programs. We can put any action information there.)

Here's the code for the loop
         MOVE      " ",SMRECKEY             ;prime the file again
         CALL      SMIOREAD                 ;get back to 1st record
         MOVE      ZERO,SM_COUNT            ;this will be running count
           CALL    SMIORKS                  ;standard I/O READKS
           MATCH   NO,SMNIF                 ;check for EOF
           BREAK IF NOT EQUAL               ;drop out if trued
           IF (ACTION_TEXT = "STOP")        ;see CANCEL was clicked
           EVENTCHECK                       ;Just make sure runtime looks
           ADD     ONE,SM_COUNT             ;count the record
         .... processing can go here .....
           CALC    PERCENT_WORK = (SM_COUNT / SM_MAX) * 100
           SETITEM FR401000ProgressBar001,0,PERCENT
         MOVE      "100",       PERCENT     ;force 100% as we exit.
         SETITEM   FR401000ProgressBar001,0,PERCENT
         .... do any wrap up processing ....
That finishes up the routine. The progress bar runs continuously and looks fine. The cancel button works to terminate the routine at any point.


Send e-mail to MMCC.

Write to MMCC Technical Support at:
MMCC, Inc.
600 W. Midland
Bay City, MI 48708
(989) 686-8860
| Home   |

© 1997 MMCC, Inc. All Rights Reserved.

Report problems or suggestions to
Site hosted by Molarnet Technologies

Since 09/15/1998