Locate into tdatabase

Locate into tdatabase

Postby Silvio.Falconi » Sat Mar 19, 2022 9:19 am

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 view
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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: Locate into tdatabase

Postby nageswaragunupudi » Sun Mar 20, 2022 12:50 pm

oDbf:Exec( < ||
LOCATE FOR YEAR(data) == nanno1
return FOUND()
> )
--> lFound

Can use
oDbf:Found()
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Locate into tdatabase

Postby Silvio.Falconi » Sun Mar 20, 2022 3:02 pm

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 view
#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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 89 guests