oribeiro Posted December 21, 2018 Report Share Posted December 21, 2018 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 ) Quote Link to comment Share on other sites More sharing options...
kapiaba Posted December 21, 2018 Report Share Posted December 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
oribeiro Posted December 21, 2018 Author Report Share Posted December 21, 2018 Obrigado João, Mas essa função retorna a quantidade de campos de uma tabela, eu preciso do número de registros ativos dela. FCount: - The function returns a numeric value which is the number of field variables available in a work area. If a work area is not used, the return value is zero. kapiaba 1 Quote Link to comment Share on other sites More sharing options...
kapiaba Posted December 21, 2018 Report Share Posted December 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
oribeiro Posted December 21, 2018 Author Report Share Posted December 21, 2018 Sputnik, Valeu pela dica em SQL. Vou usar o seu código. Quote Link to comment Share on other sites More sharing options...
Jorge Andrade Posted December 21, 2018 Report Share Posted December 21, 2018 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, Quote Link to comment Share on other sites More sharing options...
oribeiro Posted December 21, 2018 Author Report Share Posted December 21, 2018 Valeu Jorge. O código que o Sputnik enviou resolve meu problema. Eu só mandei o exemplo para o João porque ele não estava entendendo o que eu queria. Mas está resolvido. Obrigado. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.