Page 1 of 1

show only some records on Xbrowse ( nRecords, year)

Posted: Fri Sep 23, 2022 8:06 am
by Silvio.Falconi
I will display n records in an array, default 10 records
I use Tdatabase and made a Set filter as you can see on this method

Code: Select all | Expand

 METHOD Load_Data(nCount) CLASS TLOTTO
     local aTemp  := {}
     local nLastRecords,nInit,nEnd

  DEFAULT nCount := 10

    ::olotto := TArchivioLotto():New()
    ::olotto:SetOrder(1)
    ::olotto:goBottom()

    IF nCount > 0
       nInit:=::olotto:lastrec()-nCount
       nEnd:= ::olotto:lastrec()
    ENDIF

      ::olotto:Exec( <||
                SET FILTER TO   (  nInit <= ::olotto:RECNO() .AND.             ;
                                    nEnd >=  ::olotto:RECNO()    )
            return nil
            > )

       ::olotto:gotop()
       xbrowser ::olotto
     ::olotto:ArrayToDBF( atemp, , nil, .t., .t. )

     xbrowser aTemp
    return aTemp

 


Image

on this picture I use the dbf not the array


I don't understand why I don't care about a record on array aTemp, obviously I'm using the database and have an nInit/nEnd filter for the last records, by default the number of records to display is 10 until the final user should check the possibility of caricature at least fine at 500 through a combobox to select ( 10,20,30,50,100,200,300,500)


any help please

Re: show only some records

Posted: Fri Sep 23, 2022 2:52 pm
by Marc Venken

Re: show only some records

Posted: Sat Sep 24, 2022 6:58 am
by Silvio.Falconi
I made a small test to try
I wish show only nrecord and only the year = nyear selected by user

Code: Select all | Expand



#include "fivewin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//
FUNCTION Main()


   RddSetDefault( "DBFCDX" )

   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

 //  HB_LangSelect("IT")

 Test_array()

RETURN nil

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

function Test_array()
 local aDatalotto

 local nAnno   :="1871"
 loca nType    := 1
 local nRecords:= 5

 aDatalotto := Create_Array(nRecords,nAnno,ntype)

   Xbrowser aDatalotto

return nil

//----------------------------------------------------------//
function Create_Array(nCount,nyear,nType)

   local oDlg, oFont, oBrw, oGet1, oGet2, oDbf
   local nInit,nEnd,bFor
   local aTemp  := {}
   local aNew

   DEFAULT  nCount := 10  ,;
            nType:=1 //normal


    oDbf  := TDataBase():Open( nil, "LOTTO", "DBFCDX", .t. )


    // select only n records
   IF nCount > 0
       nInit:=oDbf:lastrec()-nCount
       nEnd:= oDbf:lastrec()
    ENDIF

      oDbf:Exec( <||
                SET FILTER TO   (  nInit <=  oDbf:RECNO() .AND. ;
                                    nEnd >=  oDbf:RECNO()    )
            return nil
            > )

   oDbf:GoTop()
   oDbf:FW_DbfToArray( , , , , , , aTemp )
   oDbf:close()

   xbrowser atemp    // show 6 records why ??


   // for condition year
   aNew     := {}
   AEval( aTemp, { |a| If( year(a[ 1 ]) = val(nYear) , AAdd( aNew, a ), ) } )
  * FW_DbfToArray( , , , , , , aNew)




  return  aNew





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



the first problem it show the 5 record + 1 I not understood why
then for the year not run ok

for a sample if the user want show year= 1991 and the last 100 records not run ok

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 9:19 am
by Antonio Linares
Dear Silvio,

SET FILTER is very slow

Using an index with scopes should be better

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 10:04 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

SET FILTER is very slow

Using an index with scopes should be better


with tdatabase I not Know How make it


IF nCount > 0
nInit:=oDbf:lastrec()-nCount
nEnd:= oDbf:lastrec()
ENDIF

oDbf:setscope(0,nInit)
oDbf:setscope(1,nEnd)


then for the year ?

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 10:20 am
by Silvio.Falconi
this run ok

Code: Select all | Expand


       cFilter:= "LTRIM(STR(YEAR(FIELD->DATA)))= '" + nyear + "'"
        oDbf:SetFilter(cFilter)
        oDbf:GoTop()

 


How I can add the number of records to show ?
sample only 5 records

give me error Here

nInit:=Ltrim(str(oDbf:lastrec()-nCount))
nEnd:=Ltrim(str(oDbf:lastrec()))

cFilter:= "LTRIM(STR(YEAR(FIELD->DATA)))= '" + nyear + "' .and. '"+;
nInit + "' <= Ltrim(str(FIELD-RECNO())) .and. '"+;
nEnd + "' => Ltrim(str(FIELD-RECNO())) + "'"

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 10:31 am
by Antonio Linares
Glad to see that you have recovered your strength :-)

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 10:34 am
by Silvio.Falconi
Antonio Linares wrote:Glad to see that you have recovered your strength :-)



I'm still recovering, my knee hurts

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Tue Sep 27, 2022 10:39 am
by Silvio.Falconi
also some errors

Image

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Wed Sep 28, 2022 7:24 am
by Silvio.Falconi
I found a solution!!

Re: show only some records on Xbrowse ( nRecords, year)

Posted: Wed Sep 28, 2022 6:24 pm
by Antonio Linares
+1