Keith Joubert logo - home.

Home
Contact

Binary Search
Sort Multiple Columns
Filing Functions
Extracting Excel data
Read and Write .csv files
Show Progress Messages
Send Automatic Email
Running under .hta
Setting Folder Attributes
Long-script warnings
Desktop Shortcut
ADODB & SQL queries

 

 
SHOW  PROGRESS  MESSAGES

To show progress messages during the running of programs using long-running functions, that take considerable execution time, the setTimeout() Javascript function can be used.  As you know, writing to the screen does not take place until processing is finished.  (An Alert call, for instance, halts the processing being done up to that point, and thus the pop-up is displayed.) Merely writing calls to screen-writes during program execution does not act as expected - the display only occurs once all processing has been completed.

Using setTimeout(), it is possible to halt the program execution at appropriate points, and allow messages to be displayed.  In essence, the method is simple.   Nevertheless, an example helps understanding.  The following code was used for a program running in the background, performing a series of functions at approximately 10 minute intervals.  The calling program has two form-fields used for data entry & output.  When the functions are being called, explanitory messages are displayed for each function, using these fields.



function StartUp(doc){ // The StartUp function is called on program start, or at the start of processing the "chain" of functions.
   setTimeout('DoLoop(doc,1)',100); // doc is the "document.form1." passed from the main program, referring to the screen,
 }

 function PeriodicDoLoop(doc){ // This function is used for periodic program "runs"
   doc.box2.value='Your normal default.....'; // doc.boxZZZ are fields used for data entry or display - show default message
   doc.box1.value='';  // In this example, this one is empty when the functions are not running
   setTimeout('DoLoop(doc,1)',540000); // ~ 9min (if DoLoop takes ~1min), ie, check every 10 min.
 }

 function DoLoop(doc,nxt){ // The DoLoop function controls the order of program execution
   switch(nxt){
      case 1:
         doc.box1.value='Checking/Processing...'; // doc.box1 is a field used for data entry or display - it shows a message
         doc.box2.value='The routines in function A.'; // ditto for box2....
         setTimeout('JobA(doc)',100); // Note doc is passed only if you need it in your function 'Job A'
      }
      case2:
         doc.box2.value='The routines in function B.'; // Change the message for the next function
         setTimeout('JobB(doc)',100);
       }
      case 3:
        doc.box2.value='The routines in function C.';
        setTimeout('JobC(doc)',100);
      }
      case 4:
         doc.box2.value='The routines in function D.';
         setTimeout('JobD(doc)',100);
      }
   }
}

function JobA(doc){
  //some long operation...
  DoLoop(doc,2); // ie start Job B now & display appropriate message
}

function JobB(doc,3){
  //some long operation...
  DoLoop(doc,3);  // ie start Job C now & display appropriate message
}

function JobC(doc,4){
  //some long operation...
  DoLoop(doc,4);
}

function JobD(doc){
  //some long operation...
  PeriodicDoLoop(doc); // all functions have been completed, & all messages displayed.  Display default - and wait to repeat.
}

Note:  Break the long-running functions into smaller "pieces" if you need more frequent messages.

TopTop