FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Help : Progress Bar reaches end at 33%
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 11:42 AM
Frineds,

I am using PROGRESS object while Re-indexing my DBF files. Unfortunately The progress Bar display reaches the extreme right end, even when the percentage have reached only 33%.

The percentage is calculated as
(nCurrentNtxCount/TotalNoOf Indexes) * 100

I don't know where I have went wrong

Screen Snapshot




My Code

*------------------------------------------------------------------*
Function ReIndex()
*------------------------------------------------------------------*
Local oDlg,nStyle,oProg

nStyle :=nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION ) // Removes the ? and x on the dialogue title
DEFINE DIALOG oDlg TITLE "Reindex Data Files" STYLE nStyle SIZE 600,300 PIXEL ;

@01,01 PROGRESS oProg POSITION 0 SIZE 250, 8
@03,01 BUTTON oBtn  PROMPT "Reindex" SIZE 40,12 ACTION  {oProg:SetStep( 1 ) , oProg:SetRange( 1, 100 ), DoIndexing(oDlg,oProg) }   
@03,10 BUTTON oBtn2 PROMPT "Close"    SIZE 40,12 ACTION  { CloseDbf("All"), oDlg:End() }   

ACTIVATE DIALOG oDlg CENTERED 


Close Data	
Return .T.

*------------------------------------------------------------------*
Function DoIndexing(oDlg,oProg)  // called Sam.prg
*------------------------------------------------------------------*
Local nNtxNo,n

Use DBFS
count to nNtxNo for !empty(NTXNAME)

n:=0
Sele DBFS
Go top
Do while !eof()
	if !empty(ntxkey)
		sele c
		use
		if  ! Netuse((MastPath+alltrim(dbfs->DBFNAME)),EXCLUS_OPEN,USR_WRK_AREA,5)
			*loop
	   endi
	   @04,01 say "DBF "+dbfs->DBFNAME+" Records : "+str(reccount(),6)	   
	   @05,01 say padc("Indexing on "+alltrim(dbfs->NTXKEY)+' to '+alltrim(dbfs->NTXNAME)+'.NTX',78)
	   inde on &(alltrim(dbfs->NTXKEY)) to &(Mastpath+alltrim(dbfs->NTXNAME))
	   n++
	   nPercent := VAL( STR(( n / nNtxNo ) * 100, 3, 0 ))
*	   nPercent := ( n / nNtxNo ) * 100
	   MsgInfo(str(nPercent)+"%")
	   oProg:StepIt() 
	   oProg:nPosition += nPercent

	Endif	 
	Sele dbfs
	skip
Enddo
Close Data
oDlg:End()
Return .T.


Regards

Anser
Posts: 246
Joined: Sat Mar 03, 2007 08:42 PM
Re: Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 12:09 PM

Hello,

I have also been strugling with TProgress for a few days now and I have gone back to the "old" meter class. I could not get TProgress to work properly. The Setrange() or Set() did not work ok. The bar was not set to the right position. I could not figure out how to work with TProgess.

Maybe Antonio can help us :)

Patrick

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 05:54 PM

Any other alternative way to accomplish the task.?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 06:57 PM
ProgressBars really puzzle me when used with themes :-)

See this example and check how they get filled but finally get empty:

test.prg
#include "FiveWin.ch"

function Main()

   local oDlg, oProg1, oProg2
   
   DEFINE DIALOG oDlg TITLE "Progress Bars"
   
   @ 1, 1 PROGRESS oProg1 SIZE 80, 12

   @ 1, 20 PROGRESS oProg2 SIZE 12, 50 VERTICAL
   
   @ 3,  9 BUTTON "Ok" ACTION oDlg:End()
   
   oDlg:bStart = { || Increase( oProg1, oProg2 ) }
   
   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT ( oProg1:SetRange( 0, 100 ), oProg1:SetStep( 1 ),;
                oProg2:SetRange( 0, 100 ), oProg2:SetStep( 1 ) )
   
return nil   

function Increase( oProg1, oProg2 )

   local n

   oProg1:SetPos( 0 )
   oProg2:SetPos( 0 )   
   
   for n = 1 to 100
      oProg1:StepIt()
      oProg2:StepIt()
      Sleep( 50 )
      SysRefresh()
   next
   
return nil

I really would like to know why they get empty. Any suggestions :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 07:17 PM

It looks like the nPercent you are calculating is the percent of the total number of indexes. Also you have defined the range as 0-100. So, try this--take out the first two lines and add the last line.

 // oProg:StepIt() 
 // oProg:nPosition += nPercent 
 oProg:setPos( nPercent )

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 07:24 PM

Antonio,

They work fine under XP with the blue theme (I forget the theme name).

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 07:36 PM
James,

Do you mean the "classic" theme ? (no themes). With no themes they work fine.

I got them working fine, but see the code. I can't see its logic :-)

test.prg
Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oDlg, oProg1, oProg2
   
   DEFINE DIALOG oDlg TITLE "Progress Bars"
   
   @ 1, 1 PROGRESS oProg1 SIZE 80, 12

   @ 1, 20 PROGRESS oProg2 SIZE 12, 50 VERTICAL
   
   @ 3,  9 BUTTON "Ok" ACTION oDlg:End()
   
   oDlg:bStart = { || Increase( oProg1, oProg2 ) }
   
   ACTIVATE DIALOG oDlg CENTER ;
      ON INIT ( oProg1:SetRange( 0, 100 ), oProg1:SetStep( 1 ),;
                oProg2:SetRange( 0, 100 ), oProg2:SetStep( 1 ) )
   
return nil   

function Increase( oProg1, oProg2 )

   local n

   for n = 1 to 111
      // oProg1:StepIt()
      // oProg2:StepIt()
      oProg1:SetPos( n )
      oProg2:SetPos( n )
      Sleep( 50 )
      SysRefresh()
   next
   
return nil

Here you have the EXE to test it:
http://rapidshare.com/files/142641253/progres1.zip.html

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 07:49 PM

Antonio,

>Do you mean the "classic" theme ? (no themes). With no themes they work fine.

No, I mean the "Windows XP" theme that is blue.

I agree, your latest code doesn't seem logical.

Please describe (when using the previous code) when the progress bar gets blank--at the end?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 07:52 PM

Antonio,

Your latest code works fine for me when using 111 or 100.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 08:03 PM

James,

> Please describe (when using the previous code) when the progress bar gets blank--at the end?

Yes, on the final step (from 99 to 100) it gets empty. Really strange, as the right way to do it is to use the StepIt() method.

And it only fails in Vista with themes. Without themes is ok.

At least we have a workaround. Now we need other testers feedback.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 08:22 PM

Antonio,

>Yes, on the final step (from 99 to 100) it gets empty. Really strange, as the right way to do it is to use the StepIt() method.

Hmm, maybe if you do n = 0 to 99 instead? Or, set the range from 1 to 100 instead of 0 to 100?

Sorry, I can't test it here.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 08:29 PM

James,

Could you test it with other XP themes ? thanks,

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 08:32 PM

BTW, these are the docs for ProgressBars:

http://msdn.microsoft.com/en-us/library/bb760818(VS.85).aspx

We have done lots of tests, but we may be missing something.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 09:47 PM

Antonio,

The blue theme, silver theme, and classic (no theme) all work find under XP Pro.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Help : Progress Bar reaches end at 33%
Posted: Thu Sep 04, 2008 09:56 PM

Antonio,

I also tested about a half dozen different Window Blinds themes and all the progress bars work fine. Curiously, though, only the horizontal bars use the theme graphic--the vertical ones all use the classic segmented graphic. I think this must be a Window Blinds theme bug.

But, they all do work.

Window Blinds

http://www.stardock.com/products/windowblinds/

The problem seems to be limited to Vista.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10