To Nages : locate ... 2

To Nages : locate ... 2

Postby Silvio.Falconi » Sat Apr 02, 2022 8:39 am

Nages,
I have a big archive
I need to know the number of two records and ask the end user for the start year and end year
I need it because I do statistical calculations from year x to year y

I made this test but not run ok because i did a test manually using emagdbu or fwdbu
for a sample If I search from 1939 to 2004 give me

recordfrom 1
recordto 3753

instead if I do it with this test it returns me

recordfrom 1
recordto 6510

ie it does not find it and gives me the number of the first record and the last record, but in reality it is not true






Code: Select all  Expand view  RUN

#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 "Conferma" OF oDlg SIZE 42, 12 PIXEL FONT oFont DEFAULT  ACTION ( oDlg:end( IDOK ) )
   @ 46, 92  BUTTON oBtn PROMPT "Annulla" 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
//---------------------------------------------------------//
 
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: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : locate ... 2

Postby nageswaragunupudi » Sat Apr 02, 2022 1:51 pm

Your logic itself is defective.
It is for you yourself to think and find out.
Regards

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

Re: To Nages : locate ... 2

Postby Silvio.Falconi » Sat Apr 02, 2022 3:42 pm

nageswaragunupudi wrote:Your logic itself is defective.
It is for you yourself to think and find out.



Nages,
I tried to converte a old clipper source ( summer 87) into fwh

Code: Select all  Expand view  RUN

      anno1:= "1939"
      anno2:= "1999"
      set color to GR+/N
      @ 22, 15 say "ANNO INIZIALE:" get ANNO1 picture "9999"
      @ 22, 48 say "ANNO FINALE:" get ANNO2 picture "9999"
      read
      set color to
      if (Val(anno1) > Val(anno2))
         break
      endif
      clear
      clear gets
      use lotto alias lotto
      locate for SubStr(settimana, 10, 2) = SubStr(anno2, 3, 2)
      if (Found())
         locate for SubStr(settimana, 10, 2) != SubStr(anno2, 3, 2) ;
            next 60
      endif
      if (Found())
         ultimo:= RecNo() - 1
      else
         ultimo:= LastRec()
      endif
      locate for SubStr(settimana, 10, 2) = SubStr(anno1, 3, 2)
      if (!Found())
         primo:= 1
      else
         primo:= RecNo()
      endif

 

I created this source back in 1992 and I assure you that it ran well, I know because I have always used the program until I had win xp and I could use 16bit programs in Dos in the Dos window (cmd)

On Old dbf I had a field "settimana" was of 10 CR , on new dbf I have a date field


I tried without locate

cFilter := "ltrim(str(year(data))) == '" + ltrim(str(nYear1)) +"'"
oDbf:setFilter(cFilter)
oDbf:gotop()
?oDbf:recno()
and returns the right record or at least it seems
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: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: To Nages : locate ... 2

Postby Silvio.Falconi » Sat Apr 02, 2022 4:09 pm

Nages,

Now it seem run ok

Code: Select all  Expand view  RUN
#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 "Conferma" OF oDlg SIZE 42, 12 PIXEL FONT oFont DEFAULT  ACTION ( oDlg:end( IDOK ) )
   @ 46, 92  BUTTON oBtn PROMPT "Annulla" 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:= {}
   local cFilter1,cFilter2
//---------------------------------------------------------//
   oDbf:= TDatabase():Open( ,"Lotto", "DBFCDX", .T. )
   oDbf:setorder(1)
   oDbf:gotop()
//---------------------------------------------------------//
   cFilter1    := "ltrim(str(year(data))) == '" + ltrim(str(nYear1)) +"'"
   cFilter2    := "ltrim(str(year(data))) == '" + ltrim(str(nYear2)) +"'"

            oDbf:setFilter(cFilter2)
            oDbf:gotop()
                 If year(odbf:data) = nYear2
                    nLast:= oDbf:recno() - 1
                 else
                   nLast:= LastRec()
                 endif
            oDbf:clearFilter()


            oDbf:setFilter(cFilter1)
            oDbf:gotop()
             If year(odbf:data) = nYear1
                    nFirst:= oDbf:recno() - 1
                 else
                   nFirst:= 1
                 endif

                 oDbf:close()

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



 


Image

the logic is not the same but perhaps the result is satisfactory
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: 7072
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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