KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to create a "waiting" progress bar
PRODUCT: 4D | VERSION: 2003 | PLATFORM: Mac & Win
Published On: May 6, 2004

Normally, you would use a progress bar to show some progression between a start and finish state. Sometimes, however, you may perform some action and you may not know exactly when it is going to end. Instead, to show that something is going on, you may want to display a "busy" or "waiting" progress bar. This progress bar loops between 0 and 100% continuously until some action is completed.

You will need a table and a form. In this example, the table is named "Shell" and the form is named "Form1."

Create a form with a thermometer or a Dial and name it "vBusyMeter." Then use this form method:
Case of
 : (Form event=On Load )

    ` initialize the busy meter to 0
   C_LONGINT(vBusyMeter)
   vBusyMeter:=0

    ` set the timer to execute each 15th of a second
   SET TIMER(15)

 : (Form event=On Timer )

    ` if the busy meter's value is less than 100, add to it, otherwise reset it
   If (vBusyMeter<100)
    vBusyMeter:=vBusyMeter+10
   Else
    vBusyMeter:=0
   End if

 : (Form event=On Outside Call )

    ` just cancel it if it is called from outside
   CANCEL

End case

Next create a method to open that form. Call it "ShowWaiting" :
 ` this method just opens a dialog box
C_LONGINT($winRef)

$winRef:=Open form window([Shell];"Form1")
DIALOG([Shell];"Form1")
CLOSE WINDOW($winRef)

To open the form, launch a new process using the above method:

C_LONGINT($proc)
$proc:=New process("ShowWaiting";32*1024;"WaitingProcess")

 ` loop until some unknown time
While ((Random%255)=255)
 CALL PROCESS($proc)
End while

The above example will loop until some unspecified time, at which point, the process is called from the outside which will close the progress bar. Be careful when using this technique as On Timer can hog CPU time.

Find more information about progress bars in the techical note Progress Indicator