www.icetips.com  Icetips Utilities Documentation 6/16/2016    

Progress Class Overview

Previous  Top  Next  


The Progress Class is designed to handle progress bars.  In its simplest form it can be used with 3 statements, Init, Update and Kill.  Before a loop the Init is called to initialize what progress control to use and how many records will be processed.  Update is called during the loop to update the progress bar and after the loop Kill is called to hide the progress bar. 

 

In Windows Vista Microsoft changed the way progress bars work, where the progress bar is being updated by a separate thread.  This could lead to progress bars being completely off, either completing long before the process was done, or never go all the way even if the process was done.  The Icetips Progress class uses a simple trick to make the progress bar stay right on target no matter what operating system your application is running on!

 

 

ITProgressClass          Class(ITUtilityClass),TYPE,Module('ITProgressClass.clw'),Link('ITProgressClass',_ITUtilLinkMode_),DLL(_ITUtilDllMode_)

CurrentValue               Long,Private

DisplayControls            &ITDisplayQueue

HideUnhide                 Byte

Initialized                Byte

PercentValue               Byte,Private

ProgressControl            Long,Private

TotalValue                 Long,Private

 

AddDisplayControl          Procedure(LONG pControLToDisplay,Byte pUpdateOnShow=1)

AddToCurrentValue          Procedure(Long pValueToAdd),LONG,PROC ! Adds value and returns new current value

Calculate                  Procedure                       ! Calculates percent

GetCurrentPercent          Procedure(),BYTE                ! Returns 0 - 100

GetCurrentValue            Procedure(),LONG                ! Returns CurrentValue

GetProgressControl         Procedure(),LONG                ! Returns ProgressControl

GetTotalValue              Procedure(),LONG                ! Returns TotalValue

HideControls               Procedure(BYTE pHide)           ! Hide/unhide display controls

Init                       Procedure(LONG pProgressControl, Long pTotalValue, Byte pHideUnhide=1, Byte pCanBeZeroOrOne=True)

Kill                       Procedure

ReleaseWindow              Procedure

SetCurrentValue            Procedure(Long pCurrentValue)

SetTotalValue              Procedure(LONG pTotalValue)

ShowProgress               Procedure

ShowUpdateProgress         Procedure(Long pValueToAdd)     ! Update progressbar after adding pValueToAdd to the value.

Update                     Procedure ! Calls ShowUpdateProgress(1)

                        End                      

 

 

Progress Class Tutorial Video - Part 1.  Length:  15 min, 13 sec.

Video_img_Progress_Class_1

Progress Class Tutorial Video - Part 2.  Length:  21 min, 29 sec.

Video_img_Progress_Class_2

 

 

Example 1 - loop through a queue in a tight loop:

 

ITP  ITProgressClass

I      Long

Q    Queue

F1     String(100)

     End

 Code

 Do FillQueue

 ITP.Init(?Progress1,Records(Q))

 Loop I = 1 To Records(Q)

   Get(Q,I)

   ITP.Update

 End

 ITP.Kill

 

 

Example 2 - loop through a file in a timer loop:

 

Window WINDOW('Please wait...'),AT(,,159,44),GRAY

       PROGRESS,USE(?Progress1),AT(4,6,151,15),RANGE(0,100)

       BUTTON('Cancel'),AT(57,26,45,14),USE(?CancelButton),HIDE

     END

ITP  ITProgressClass

RecsPrTimer Equate(100)

Done        Byte

 Code

 Open(Window)

 Open(MyFile)

 Set(MYF:MyKey)

 ITP.Init(?Progress1,Records(MYF:MyKey),True) !! Initialize and tell it to handle more controls...

 ITP.AddDisplayControl(?CancelButton,False)   !! ... and add the ?CancelButton...

 ITP.HideControls(False)                      !! ... and unhide all handled controls while the progress is running

 Accept

 Case Event()

 Of EVENT:OpenWindow

   Window{Prop:Timer} = 1

 Of EVENT:Timer

   If Done

     Window{Prop:Timer} = 0

     Break !! Break Accept loop

   End

   Loop RecsPrTimer Times

     Next(MyFile)

     If ErrorCode()

       Done = True

       Break

     End

     !! Do something with the MYF: Record

     ITP.Update                               !! Update the progress bar

   End

   Case Field()

   Of ?CancelButton

     Case Event()

     Of EVENT:Accepted

       Done = True

       Window{Prop:Timer} = 0

       Break !! Break Accept Loop

     End

   End

 End

 ITP.Kill                                     !! Terminate class, hide progress bar and any additional controls

 Close(MyFile)

 Close(Window)

 



Direct link to this page: http://www.icetips.com/manuals/utilities/progress_overview.htm