How to use a Indicator control

lloydflloydf Member Posts: 73
Hi there could anyone please give a simple example of how to use the indicator control.
I have a blank form with some buttons which will trigger some processing.
e.g. I will be looping through the customer table and modifying some data and I would like to place an indicator on the form and have it display the progress of the processing.
any help would be appreciated

thanks

Comments

  • awarnawarn Member Posts: 261
    What I use (which is not the progress bar but I ifnd it a bit simpler), is code like below. I don't know the progress bar offhand, maybe someone else can post it. The example is looping through customers but you should be able to get the picture.

    //Window is a variable of type dialog, icount is an integer

    Window.open('Processing customer #1######, #2###### of #3######');
    window.update(3,customer.count); //control 3 is the total count of the records you are scrolling through

    icount := 0;

    //filters
    if customer.findfirst then repeat
    icount := icount + 1;
    window.update(1,customer."no."); //update this control with the customer no
    window.update(2,count); //update this control with the current count

    //all of your other processing
    until customer.next = 0;

    window.close;


    -a
  • lloydflloydf Member Posts: 73
    Thanks for your reply it is appreciated however I need to use the indicator control as I need to embed it on a form.
  • SavatageSavatage Member Posts: 7,142
    Here's another example of the Progress Bar

    do the following
    declare 3 variables:
    window of type dialog
    TotalRec of type integer
    CurRec of type integer


    in OnPreDataItem
    window.OPEN('Processing @1@@@@@@@@'); 
    TotalRec := COUNT;
    
    in AfterGetRecord
    CurRec := CurRec + 1; 
    window.Update(1,ROUND(CurRec / TotalRec * 10000,1));
    
    in OnPostDataItem
    window.CLOSE;
    

    Whatever processing you are doing it's going to have to:
    Get a record
    Do something with the record
  • lloydflloydf Member Posts: 73
    OK I have roughly worked out how to use this however I do not understand how I can dynamically apply the minValue and the maxValue properties which are key to the control functioning. The SourceExpr is set to a counter variable which is incremented as I loop through each record being processed however if I attempt to assign a variable to maxValue or minValue I get an error.
  • DenSterDenSter Member Posts: 8,305
    The progress bar works with integer numbers 0-10000, that's why it goes (currentnumber/totalnumber * 10000). Your dynamic control variable will be the total number, the current number is the one you increment as you loop, and by multiplying the result by 10000 you control the progress indicator. You need to round to the nearest whole number because it only takes integer. Don't forget to catch division by zero.
  • lloydflloydf Member Posts: 73
    Denster, Thanks for your reply. please forgive my ignorance. Firstly I am trying to use the indicator control. The application designer guide mentions three key properties: minValue, maxValue and SourceExpr. The only property that I can assign a variable to is SourceExpr.
    If I give you the scenario that I want to loop through all the customer records and using a record variable called recCustomers and a counter variable called intCount. Using the code below how can I get the indicator control to work?

    intCount:=0;
    recCustomers.init;
    IF recCustomers.FIND('-') THEN BEGIN
    REPEAT
    intCount:=intCount + 1;
    UNTIL recCustomers.Next=0;
    END;


    Do I set the SourceExpr to intCount? And how do I set minValue, maxValue?
  • DenSterDenSter Member Posts: 8,305
    Here's a little example. Paste this into a new text file, and import it into your database. I used form number 60000, so if that is already taken, you need to renumber it first.
    OBJECT Form 60000 Progressbar Test
    {
      OBJECT-PROPERTIES
      {
        Date=12/02/07;
        Time=11:32:40 AM;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        Width=3190;
        Height=2420;
      }
      CONTROLS
      {
        { 1000000000;Indicator;220;220  ;2750 ;440  ;Name=MyProgressBar;
                                                     SourceExpr=ProgressCount;
                                                     MinValue=0;
                                                     MaxValue=10000 }
        { 1000000001;CommandButton;550;880;2200;550 ;Name=btnShowProgress;
                                                     CaptionML=ENU=Show Progress;
                                                     OnPush=BEGIN
                                                              // first reset the counters
                                                              ResetProgressBar();
    
                                                              // Set the total count, in real life this is where you'd set it to the total
                                                              // number of customers for instance
                                                              TotalCount := 1000;
    
                                                              // then start your loop
                                                              REPEAT
                                                                CurrentCount += 1;
                                                                ProgressCount := ROUND(CurrentCount/TotalCount * 10000,1);
                                                                CurrForm.MyProgressBar.UPDATE;
                                                              UNTIL CurrentCount = TotalCount;
                                                            END;
                                                             }
        { 1000000002;CommandButton;550;1650;2200;550;Name=btnReset;
                                                     CaptionML=ENU=Reset;
                                                     OnPush=BEGIN
                                                              ResetProgressBar();
                                                            END;
                                                             }
      }
      CODE
      {
        VAR
          TotalCount@1000000002 : Integer;
          CurrentCount@1000000003 : Integer;
          ProgressCount@1000000000 : Integer;
    
        PROCEDURE ResetProgressBar@1000000000();
        BEGIN
          ProgressCount := 0;
          CurrentCount := 0;
          TotalCount := 0;
          CurrForm.MyProgressBar.UPDATE;
        END;
    
        BEGIN
        {
          The MinValue and MaxValue properties are hardcoded properties, so you need to set those
          from the properties window. I use 0 and 10000 because they are the same as the progress
          indicator on the dialog window. The SourceExpr property is your control variable, which
          is also an integer that displays the progress between 0 and 10000. Because in real life
          you can never tell the counters upfront, you have to use a dynamic calculation, expressed
          as a percentage of the maxvalue.
    
          With a large number of entities, you might want to update the progressbar only every so many
          times, for instance just 10 times, because repainting the form takes a lot of processing
    
    
          Variables:
          TotalCount is the count of the total entities. If you need to loop through all customers,
          then you set this to Customer.COUNT for instance.
    
          CurrentCount is where you are in the loop
    
          ProgressCount is an integer number between 0 and 10000, which are the min and max values
    
          Process:
          All that is available really is an UPDATE method of the control, so that's all you can do.
          Loop through your entity, keep track of the ProgressCount and UPDATE your progress bar.
        }
        END.
      }
    }
    
  • lloydflloydf Member Posts: 73
    Denster, What can I say!! That is an absolutely fantastic example. Thanks for taking the time to create this incredibly useful example. I am sure that many people will benefit from this.
  • DenSterDenSter Member Posts: 8,305
    You're welcome. I was writing an elaborate reply and realized it would take about the same time to put together a little sample. Glad I could help :mrgreen:
Sign In or Register to comment.