Jump to content
Fivewin Brasil

Contador de Registros


oribeiro

Recommended Posts

Pessoal,

Existe no xharbour alguma função que retorne apenas o número de registros filtrados numa tabela?

O RecCount() e o LastRec() retornam o total de registros na tabela sem considerar o Scope nem o Filter. Existe algum outro comando que faça isso?

Eu desenvolvi a função abaixo para fazer isso, mas se tiver um comando nativo é mellhor:

********************************************************************************************
Function oaRecCount() // Calcula o número de registros ativos no arquivo (considera ordscope, setfilter, etc.)
********************************************************************************************
   Local nRec := 0
   Local nReg
   if Used()
      nReg := RecN()
      DbGoTop()
      Do While !Eof()
         SysRefresh()
         nRec = nRec + 1
         DbSkip()
      EndDo
      DbGoTo( nReg )
   endif
Return( nRec )

 

Link to comment
Share on other sites

Maybe:

        USE Branch INDEX Branch NEW        SEEK 100        USE Sales INDEX SalesBranch NEW        SEEK 100        COUNT TO Branch->Count WHILE Branch = 100        USE Sales INDEX Branch NEW        TOTAL ON &(INDEXKEY(0)) FIELDS Amount TO Summary
	PROCEDURE Main()
	USE tests NEW
? "This database have", tests->( FCOUNT() ), "Fields"
USE
RETURN
	

Link to comment
Share on other sites

Não entendi o que vc quer dizer com SCOPE ou FILTER???

#include "FiveWin.ch"
	FUNCTION Main()
	   LOCAL nTotReg := 0
	   SET DELETED ON
	   USE CUSTOMER NEW
   GO TOP
	   ? CUSTOMER->( RecCount() )  // 508
	   CLOSE ALL
	   USE CUSTOMER NEW
   GO TOP
	   WHILE .NOT. EOF() // MESMA COISA QUE RECCOUNT()
	     SYSREFRESH()
	     nTotReg++
	     SKIP
	   ENDDO
	   ? nTotReg                   // 508
	   CLOSE ALL
	RETURN NIL


 

Link to comment
Share on other sites

Oscar, blz? Mas se vc abriu a tabela pra fazer qualquer processo com o Scope ou Filter e precisa contar os registros, então, a instrução que o amigo passou só faz isso, ou seja,contar os registros, se vc precisar fazer mais ações teria que fazer novo SELECT.

Não seriam melhor vc abrir a sua tabela com os filtros ou Scope que vc precisa e usar o comando abaixo, pois, a sua tabela já tem os registros selecionados, basta vc contá-los:

COUNT TO <varName> ;
        [<Scope>] ;
  [WHILE <lWhileCondition>] ;
    [FOR <lForCondition>]

Ou criar um SELECT aninhado com os filtros e a contagem dos registros ao mesmo tempo?

[]s,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...