Invoke a Quick Thermometer Bar for your Apps

by Carl Warner

I had a request to come up with something to show some end users where a long batch job was as far as completion.   If you don't throw some visual cue out there, they occasionally think the app has frozen up and they end up doing a premature re-boot.  Ouch!!  The task at hand was just to add it to some existing code and no one wanted to have anything too fancy or intricate.  Plus, every so often, I see a request from someone in the Fox community of how to create a thermometer bar or progress bar in their apps.  And, quite honestly, I have seen plenty of apps done by others that use no progress bars at all as though they felt it was too hard or too confusing on how to use one.  So, if you don't use one, let's take the mystery out of it.  If you do, this probably isn't for you unless you don't use a quick and dirty method and you haven't bothered to look for one.

The good news is that it is very easy to call up one and to increment it.  Of course, you can do all sorts of calculations to make the incrementing very precise.  But, in a quick and dirty world, that is unnecessary.  Just make a best guess as to your progress points and then just do it.

I tested this with VFP6 so I'm sure what I'm going to tell you to do is good as far back as that version.  I no longer have VFP3 or VFP5 installed anywhere.  But, I suspect they may also have this available in their Foundation Classes as well.


What Do You Have To Do To Make It Work Quickly?

In a VFP project, add the _therm class library to the project.  [I had mine in a subfolder called "Libs" just below the application folder level.] 

Then, in any other project app routine, use the following snippets of code to make it work when you want it:

 
To initialize the thermometer, you could simply add the following: Here's what the code on the left generates on the screen:
txtTitle = "Progress of Data Processing Routine"
loTherm =
NewObject("_thermometer","libs\_therm","",txtTitle)
lotherm.
Show
   
Then to increment sections of your routine as it moves through your code:  
Place a line of code where you want to show the user progress  
loTherm.Update( 10, "Processing Calculations...")
loTherm.Update( 30, "Processing Details...")
loTherm.Update( 60, "Processing Summary Level Info...")
loTherm.Update( 80, "Processing Logging Routine...")
loTherm.Update(100, "Processing Is Complete...")

If you have a user that needs sound cues as well for an especially long process, you can easily add those at those same progress locations as the thermometer bar is incremented.  And, if you have an understanding fun-loving user in an understanding fun-loving company (or you just want to surprise the heck out of someone because you're sure you won't get reprimanded or fired), you can add something like the following to sound off.  If you simply copy and paste this code into your VFP Command Window and your VFP session is at the root folder of VFP where the _therm.vcx is right below it in the FFC folder, you can highlight this code block and right click it in the Command Window and select "Execute Selection".

_SCREEN.MOUSEPOINTER = 11
** supply your own attention grabbing sound files to replace the two I use here
IF FILE("C:\Program Files\Windows NT\Pinball\SOUND999.WAV")
   SET BELL TO "C:\Program Files\Windows NT\Pinball\SOUND999.WAV"
ENDIF

txtTitle = "Progress of Data Processing Routine"
loTherm  =
NewObject("_thermometer","FFC\_therm","",txtTitle)
lotherm.
Show

??
CHR(7)   && You may have to "SET CONSOLE ON" to make this work and then "SET CONSOLE OFF" as a cleanup command
=INKEY(2,"HM")

loTherm.Update( 10, "Processing Calculations...")
?? CHR(7)
=
INKEY(2,"HM")

loTherm.Update( 30, "Processing Details...")
?? CHR(7)
=INKEY(2,"HM")

loTherm.Update( 60, "Processing Summary Level Info...")
?? CHR(7)
=INKEY(2,"HM")

loTherm.Update( 80, "Processing Logging Routine...")
?? CHR(7)
=INKEY(2,"HM")

loTherm.Update(100, "Processing Is Complete...")
IF FILE("C:\Program Files\Windows NT\Pinball\SOUND38.WAV")
  
SET BELL TO "C:\Program Files\Windows NT\Pinball\SOUND38.WAV"
ENDIF
?? CHR(7)

=
INKEY(2,"HM")
SET BELL TO
loTherm.
Release
ACTIVATE SCREEN
_SCREEN.MOUSEPOINTER
= 0

If the above is not sophisticated enough for you or you just are curious and want to see other references on the topic, here they are:

MORE ON THERMOMETER/PROGRESS BARS IN VFP--

HOWTO Create a Thermometer Bar in Visual FoxPro
http://support.microsoft.com/default.aspx?scid=kb;en-us;139388

HOWTO Create a Progress Indicator Using ThreeD Panel Control
http://support.microsoft.com/default.aspx?scid=kb;en-us;167192

HOWTO Display a Progress Bar in a Status Bar
http://support.microsoft.com/default.aspx?scid=kb;en-us;259296

Demo Script Using the ProgressBar Control in Visual FoxPro
http://www.dfpug.de/loseblattsammlung/migration/demos/progbar.htm

Microsoft Visual FoxPro Using the ProgressBar Control
http://msdn.microsoft.com/vfoxpro/techinfo/articles/v5/progbar.asp

Creating a Thermometer Class With Code - Pinter Consulting
http://www.lespinter.com/PC/ShowArticle.aspx?ArtNum=223

Progress Bar Class - Visual FoxPro Wiki
http://fox.wikis.com/wc.dll?Wiki~ProgressBarClass~VFP

HOWTO: Use Component Gallery to Build an Application
http://support.microsoft.com/kb/191502/en-us

Use the ActiveX Progress Bar OCX Control
http://support.microsoft.com/kb/254478/en-us

Carl Warner