Page 1 of 1

Updating SAY When Indexing

Posted: Thu Aug 03, 2006 6:35 pm
by Bill Simmeth
Hi,

Perhaps someone can see a solution to my problem. I have put together a file maintenance section to reindex files on the PocketPC if necessary. I would like to give the user feedback with a status SAY and a progress bar. The progress bar works flawlessly, but updates to the SAY are blocked until the indexing is complete. The sample below (sorry for the length) works with the customer.dbf in the \SAMPLES directory.

Thanks in advance!

Code: Select all | Expand

#include "FWCE.ch"

REQUEST DBFCDX

******************************************************************************
FUNCTION Main()
******************************************************************************
LOCAL oWnd, oBar, oSay

   DEFINE WINDOW oWnd TITLE "Index"

   @ 40, 5 BUTTON "Index" OF oWnd SIZE 80, 25 PIXEL ;
           ACTION ( oSay:setText( "Now indexing..." ), DoIndex( oBar, oSay ) )

   @ 160, 5 SAY oSay PROMPT "File Progress..." OF oWnd SIZE 230, 20 PIXEL

   @ 180, 5 PROGRESS oBar OF oWnd SIZE 230, 15 PIXEL

   oBar:SetRange( 0, 100 )
   oBar:nPosition := 0

   ACTIVATE WINDOW oWnd

RETURN NIL

******************************************************************************
Procedure DoIndex( oBar, oSay )
******************************************************************************

   Select 0
   USE ( CurDir() + "\customer" ) VIA "DBFCDX" Exclusive

   oSay:setText( "Indexing to tag LAST..." )
   ordCreate( ( CurDir() + "\customer" ), "LAST", "last", {|| Ndxbar(oBar,1), last } )

   Sleep( 2000 )
   oBar:nPosition := 0
   Sleep( 2000 )

   oSay:setText( "Indexing to tag FIRST..." )
   ordCreate( ( CurDir() + "\customer" ), "FIRST", "first", {|| Ndxbar(oBar,1), first } )

   Sleep( 2000 )
   oBar:nPosition := 0
   Sleep( 2000 )

   oSay:setText( "Indexing to tag CITY..." )
   ordCreate( ( CurDir() + "\customer" ), "CITY", "city", {|| Ndxbar(oBar,1), city } )

   CLOSE ALL

   Sleep( 2000 )

   MsgInfo( "Done!" )

Return

******************************************************************************
FUNCTION Ndxbar(oBar,nEvery)
******************************************************************************
LOCAL nLastrec

STATIC nCounter := 0

DEFAULT nEvery := 10

   IF ++nCounter >= nEvery
      nCounter := 0
      nLastrec := lastrec()
      IF nLastrec > 0
         oBar:nPosition := ((recno()/nLastrec)*100)
      ENDIF
   ENDIF

RETURN nil

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( SLEEP )
{
    Sleep( hb_parnl( 1 ) );
}

#pragma ENDDUMP

Posted: Thu Aug 03, 2006 8:14 pm
by Antonio Linares
Bill,

Place a call to SysRefresh() from Ndxbar(). You may fine tune it to not call it everytime as it is time consuming.

Posted: Thu Aug 03, 2006 8:19 pm
by Bill Simmeth
Ah, very good. This solves it. Thank you for this tip!