*** New Note ***

I didn't really expect this thing to go over so well!  As a result I have
found myself fine tuning it due to a number of performance questions raised.

I guess I better start with the version numbers!

Um, lets call this one 2.5.  What the hell.

*** End Note ***

The purpose of STATWIN is to display a "percentage processed," or "status" 
window, complete with visual indicator bar.  I applaud Jim Schaffner for 
implementing this idea using Clipper.

However, as is usually the case when I stumble across good code, I found some 
elements aesthetically lacking.  With apologies to Jim, I have hacked up the
code a bit to help satisfy my desire to produce a more beautiful and robust
utility.

There are many enhancements to the original, but I will spare you the details.
Just try it out.  If you have used the original, the differences will be
readily apparent.  The gist of the code is still Jim's, though.

I have also included a better TEST program, which shows all the features
available from STATWIN.

Compile both TEST.PRG and STATWIN.PRG, then link.  Have fun!  I hope you
enjoy this great little utility!  If you have any other ideas to improve
the code (either functionally or aesthetically) I'd be glad to hear from you.

Cai Campbell
Compuserve ID 72622,1771

*
*   One problem inherent in a utility such as StatWin is its inability to
*   report progress on "internal" processes such as indexing or appending.
*
*   The following code demonstrates a method I have included to circumvent 
*   this problem.  However, since it utilizes a couple of public variables,
*   purists may frown on this approach.
*
*   The philosophy behind this approach may be applied to a number of other
*   situations where "internal" processes are being used.
*

*
*  Procedure: ShowIndex
*
*  Demonstrates the method needed to use StatWin to display percent bar while
*  a large DBF file is being indexed or reindexed.
*

PROCEDURE ShowIndex

   USE BigFile NEW      // Open the DBF file
   StatInit ( 8, 25 )   // Initialize the Status Window
   
   cStatMsg := "Indexing:"  // Public variable to store Status Window Message
                            // (optional)

   INDEX ON INDEXKEY + StatWin ( LASTREC(), nStatCounter, cStatMsg ) TO IndexFile

   //  The above index command is the key to making the status bar work.
   //  StatWin is tied directly to your index.  As such, every time BigFile is 
   //  reindexed (or processed in any way, for that matter), the Status
   //  Window will be displayed (If you forget to reinitialize the Status
   //  Window with StatInit, the resulting window will be less than pleasing.)
   //  You can stop display of the Status Window by explicitly reindexing the 
   //  file without making StatWin part of the index.
   //
   //  nStatCounter is a Public variable definded in STATWIN.PRG.  It keeps
   //  track of the current state of the process.

   StatExit()
             
   StatInit ( 8, 25 )       // This section is similar to that above, but shows
   cStatMsg := "Reindexed:" // how you would go about reindexing the file while
   REINDEX                  // showing the Status Window.  This assumes that the
   StatExit()               // the file has been indexed once before using the
                            // process outlined above.  Note that cStatMsg can
                            // be changed to display a different message every
                            // time you reindex the file.
   CLOSE BigFile

RETURN

*
*  Procedure: ShowAppend
*
*  Demonstrates the method needed to display a Status Window while appending
*  from a large file.
*
   
   LOCAL nFileSize      // Size of source file (in number of records)

   cStatMsg := "Appending:"  // Public variable declared in STATWIN.PRG

   USE TargFile NEW     // Open the DBF file
   ZAP                  // Assuming you want to clear the target file
   StatInit ( 8, 25 )   // Initialize the Status Window

   nFileSize := // If appending from an ASCII SDF file, nFileSize equals the 
                // size of file (in bytes) divided by line length (including
                // carriage return and linefeed.)  This gives the total number
                // of records to be appended.  
                //
                // If appending from an ASCII delimited file, nFileSize will be
                // more difficult to compute.  One solution is to search the
                // source file for the total # of carriage return/linefeeds, 
                // thus giving you the total number of records to be appended.
                // (See accompanying LINCOUNT.PRG)
                //
                // If appending from another DBF file, nFilSize simply 
                // equals the number of records in the source file.
   
   INDEX ON StatWin ( nFileSize, nStatCounter, cStatMsg ) TO IndexFil

   //  The above index command is the key to making the status bar work.  The
   //  function StatWin is directly tied to the index.
   //
   //  Here, IndexFile is temporary and is used only to allow displaying of the
   //  Status Window.

   APPEND FROM ( "SOURCE.TXT" ) SDF  // assuming ASCII System Data Format

   StatExit()  

   CLOSE TargFile INDEXES           // close the temporary index

   FERASE ( "INDEXFIL.NTX" )        // erase the temporary index

   CLOSE TargFile

