progress bar

progress bar

Postby brewster » Fri Jan 25, 2013 2:02 pm

Hi,
Currently I am building a .dbf of filenames from a Windows folder and its subfolders.

I wish to have a progress bar to display "while" the .dbf is being populated.

I have inserted a progress bar from the testmex.prg sample into my code.

Problem is the progress bar dialog is only displayed upon completion, not while the .dbf is building.

I am unsure how to accomplish the task.

At the risk of leaving something out , I include the entire function.

Any help appreciated,
Bruce S.

FWH 12.06 June 2012
Harbour 3.1.0 Rev.17222
bcc582
Clipper - 5.3b

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Func heat_update() // Date : 10/11/12
// Use : Assemble Q:\data folder and file information
// for millcerts

local aFolders
local nFol_len

local nOffset := 3 // set at 3 to bypass . & .. parent <dir>
local nIndex := 1

local cFol_nam
local nFol_max


local aSub_Fldr
local nSub_max := 0
local nSub_index := 3 // set at 3 to bypass . & .. parent <dir>

local nRec_ctr := 0
local cSto

local cStart := time()
local cStop
local cElapsed

local oPrg
local oProg1


local oDlg
local nActual := 0
local oMeter
local nTotal
local nTimes := 0



// stats dialog
local oStat
local fntArial
local oSay
local cStat_msg

Local hFile
Local aInfo

local cCert_seg := "q:\data\millcert\"
local cFile := "m_cert.dbf"

local times
local nActual3 := 10 //6000
local ometer3


USE ( cCert_seg + cFile) alias MC
DELE ALL
PACK


//msginfo( cCert_seg,"Cert" )


// build array of millcert folder names
aFolders := directory( cCert_seg, "D" )

nFol_len := len(aFolders) // count all folders

nFol_len ++ // add one to cover the one we are starting on


If lIsDir( cCert_seg ) // does folder exist

//MTR


DEFINE FONT fntArial NAME "Arial" SIZE 0, -12 //BOLD


DEFINE DIALOG oDlg FROM 14,65 TO 21, 93 ;
TITLE " Record total " //+ trans(lastrec(),'999,999')



// meter 3 from testmex.prg w h
@ 5, 5 METEREX oMeter3 VAR nActual3 SIZE 100, 10 TOTAL 100 PIXEL;
GRADIENT CHUNK { { 1/2, nRGB( 255, 251, 229 ), nRGB( 250, 223, 143 ) } ,;
{ 1/2, nRGB( 244, 194, 51 ), nRGB( 252, 235, 173 ) } };
GRADIENT TRACK { { 1/2, nRGB( 198, 203, 213 ), nRGB( 219, 224, 233 ) } ,;
{ 1/2, nRGB( 224, 238, 237 ), nRGB( 224, 238, 237 ) } };
ROUND LINECOLORS CLR_BLACK, CLR_WHITE



Do while nOffset < nFol_len

cFol_nam := aFolders[nOffset][1] // current folder name

// Sub folder info

// directory of sub folder
aSub_Fldr := directory( cCert_seg + cFol_nam + "\*.*","D")

nSub_max := len(aSub_Fldr) // # of files
// ?minus . & ..
// will I need when sub folders are involved


Do while nSub_index <= nSub_max // store sub folder contents

APPEND BLANK

cSto := iif(upper(right(aSub_Fldr[nSub_index][1],3)) = "PDF" ,"FL","FD")


Repl;
MC->heat with aSub_Fldr[nSub_index][1],;
MC->sto with cSto ,;
MC->pri_supl with left(cFol_nam,8)


Automatic( oMeter3, @nActual3 )


nRec_ctr++ // may be out by . & .. ??
nSub_index++



Enddo //sub_max


nSub_index := 3 // set to 3 to bypass . & ..
nOffset++

Enddo //nFol_len

dbcommit()


else

// notify if no folder available
msginfo( "Q:\data\millcert does not exist","Info" )
return nil


endif

////////////////////////////////////////////
// display processing stats

cStop := time()
cElapsed := cStop - cStart


@ 1.00 , 1.0 say trans(lastrec(),'999,999') + " records " ;
FONT fntArial SIZE 180,80

@ 1.75 , 1.0 say trans(nRec_ctr ,'999,999') + " processed " ;
FONT fntArial SIZE 180,80

@ 2.50 , 1.5 say substr(cElapsed,1,5) + " seconds " ;
FONT fntArial SIZE 180,80


ACTIVATE DIALOG oDlg

fntArial:End()


DBCLOSEALL()

return nil // heat_update
//----------------------------------------------------------------------------//

FUNC Automatic( oMeter, nActual )

LOCAL n
LOCAL nFrom := nActual

FOR n = nFrom TO oMeter:nTotal step 0.001
nActual = n
oMeter:Set( nActual )
NEXT
nActual = oMeter:nTotal
oMeter:Set( nActual )

RETURN NIL

//--------------------------------------------------------

<<<<<<<<<<<<<<<<
brewster
 
Posts: 43
Joined: Wed Jun 20, 2012 4:07 am

Re: progress bar

Postby Euclides » Sat Jan 26, 2013 8:05 pm

Bruce, you can start with this example
Code: Select all  Expand view

/*  SAMPLES\PROGTIME.PRG modified  */
#include "FiveWin.ch"

function Main()
local oDlg, oProg, aFiles:=directory(".\"), oSy, cFile:=""
   DEFINE DIALOG oDlg TITLE HB_Curdrive()+"
:\"+Curdir()+" Directory Scan"
   @ 1, 1 PROGRESS oProg POSITION 0 SIZE 150, 10
   @ 2, 10 say oSy VAR cFile size 100, 12
   @ 2.5,  6 BUTTON "
Scan" ACTION DoScan(aFiles, oProg, oSy, @cFile)
   @ 2.5, 14 BUTTON "
End" ACTION oDlg:End()
   ACTIVATE DIALOG oDlg CENTER
return nil  
*
Function DoScan(aFiles, oProg, oSy, cFile)
local nI
   oProg:nPosition=0
   oProg:SetRange( 0, len(aFiles))
for nI=1 to len(aFiles)
    oProg:nPosition += 1
    cFile=upper(aFiles[nI, 1])
    oSy:refresh()
    syswait()
next
return nil

the "syswait()" is only there to slower the operation.
Regards, Euclides
User avatar
Euclides
 
Posts: 156
Joined: Wed Mar 28, 2007 1:19 pm

Re: progress bar

Postby brewster » Sun Jan 27, 2013 5:50 pm

Euclides,

Thank you, I will pursue

Bruce
brewster
 
Posts: 43
Joined: Wed Jun 20, 2012 4:07 am


Return to FiveWin for CA-Clipper

Who is online

Users browsing this forum: No registered users and 7 guests

cron