Page 1 of 1

Locate into tdatabase

Posted: Sat Mar 19, 2022 9:19 am
by Silvio.Falconi
the old program (fw+clipper) asks for the year of start and year of end of the research (nAnno1 and nAnno2),
if it does not find them, it sets the first record as default in the nPrimo variable and the last record in the nUltimo variable
if it finds them, it saves the record corresponding to the record found with nYear1 in the variable nPrimo and the record corresponding to the record found with nYear2 in the variable nUltimo.

in the old program i used the locate command but now using tdatabase or tdata i can't get it to work

these are the lines of code from the old program

Code: Select all | Expand

locate for year(data) = nanno2
      if (Found())
         locate for year(data) != nanno2 ;
            next 60
      endif
      if (Found())
         nultimo:= RecNo() - 1
      else
         nultimo:= LastRec()
      endif
      locate for year(data) = nanno1
      if (!Found())
         nprimo:= 1
      else
         nprimo:= RecNo()
      endif


how can i do to convert this code to tdatabase?

Re: Locate into tdatabase

Posted: Sun Mar 20, 2022 12:50 pm
by nageswaragunupudi
oDbf:Exec( < ||
LOCATE FOR YEAR(data) == nanno1
return FOUND()
> )
--> lFound

Can use
oDbf:Found()

Re: Locate into tdatabase

Posted: Sun Mar 20, 2022 3:02 pm
by Silvio.Falconi
nageswaragunupudi wrote:oDbf:Exec( < ||
LOCATE FOR YEAR(data) == nanno1
return FOUND()
> )
--> lFound

Can use
oDbf:Found()


Nages,
I try to create a small function to return me an array with the number of first record and last record, but I not understood well because not run ok

Code: Select all | Expand

#include "FiveWin.ch"

REQUEST DBFCDX

Function test()
Local oDlg,oFont
local nYear1:= 1939,nYear2:= 2022
local aRecords:= {}

   DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 8
   DEFINE DIALOG oDlg FROM 100, 100 TO 230,376;
                 TITLE "Selection year" PIXEL FONT oFont

   @ 12, 10 SAY "From year:" OF oDlg SIZE 17, 8 PIXEL FONT oFont
   @ 10, 47 GET nYear1     OF oDlg SIZE 44, 12 PIXEL FONT oFont picture "9999"
   @ 26, 10 SAY "to year" OF oDlg SIZE 32, 8 PIXEL FONT oFont
   @ 24, 47 GET nYear2   OF oDlg SIZE 44, 12 PIXEL FONT oFont picture "9999"


   @ 46, 48  BUTTON oBtn PROMPT "OK" OF oDlg SIZE 42, 12 PIXEL FONT oFont DEFAULT  ACTION ( oDlg:end( IDOK ) )
   @ 46, 92  BUTTON oBtn PROMPT "EXIT" OF oDlg SIZE 42, 12 PIXEL FONT oFont CANCEL   ACTION ( oDlg:end( IDCANCEL ) )


ACTIVATE DIALOG oDlg CENTERED

   IF oDlg:nresult == IDOK
      if ((nYear1) > (nYear2))
         return nil
      endif
          arecords:= Locate_Records(nYear1,nYear2)
          xbrowser aRecords
   Endif
return nil

//----------------------------------------------------//
Function Locate_Records(nYear1,nYear2)
   local oDbf,nFirst,nLast
   local aLocate:= {}

   oDbf:= TDatabase():Open( ,"Lotto", "DBFCDX", .T. )
   oDbf:setorder(1)
   oDbf:gotop()

  oDbf:Exec( < ||
          LOCATE FOR YEAR(oDbf:data) == (nYear2)
          return FOUND()
          > )


 if (oDbf:Found())
      oDbf:Exec( < ||
          LOCATE FOR YEAR(oDbf:data) != (nYear2)  next 60
          return FOUND()
          > )
       Endif


    if (oDbf:Found())
         nLast:= oDbf:RecNo() - 1
      else
         nLast:= oDbf:LastRec()
      endif

    oDbf:Exec( < ||
          LOCATE FOR YEAR(oDbf:data) == (nYear1)
          return FOUND()
          > )


      if (!oDbf:Found())
         nFirst:= 1
      else
         nFirst:= oDbf:RecNo()
      endif
      oDbf:close()

    AaDd( aLocate,{nFirst,nLast})
   return aLocate
//---------------------------------------------------------//

 


give me allways 1,6510
I can send you the dbf