Nages Help for locate --- Resolved

Nages Help for locate --- Resolved

Postby Silvio.Falconi » Sun Apr 17, 2022 10:27 pm

On oldest Prg I use
Code: Select all  Expand view
Function Locate_Records(anno1,anno2)
   local aLocate:= {}
   LOCAL nFirst,nLast


   USE LOTTO ALIAS LOTTO

   locate for year(LOTTO->data) = anno2

      if (Found())
         locate for year(LOTTO->data) != anno2 ;
            next 60        // because once the extractions were 60
      endif

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

      locate for year(LOTTO->data) = VAL(anno1 )

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

      AaDd( aLocate,{nFirst,nLast,anno1, anno2})

      XBROWSER  aLocate
      RETURN NIL
 


and it run ok as you can see here ( for a sample I seach the year 1946) I have the right record number ( column A)

Image


If I select for another sample year 2009 I have the right record number ( column A) as you can see here

Image




When I try to convert it with tdatabase it not run ok

Code: Select all  Expand view


Function Locate_Records2(anno1,anno2)
   local aLocate:= {}
   LOCAL nFirst,nLast, oDbf


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

   oDbf:Exec( < ||
           locate for year(oDbf:data) = anno2
          return FOUND()
          > )

          if (Found())
                      oDbf:Exec( < ||
                                     locate for year(oDbf:data) != anno2 ;
                                                      next 60        // // because once the extractions were 60
                                        return FOUND()
                                         > )

      endif



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

       oDbf:Exec( < ||
                                locate for year(oDbf:data) = VAL(anno1 )
                               return FOUND()
         > )


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

      AaDd( aLocate,{nFirst,nLast,anno1, anno2})

      XBROWSER  aLocate
      RETURN NIL


How I can resolve it ?


this is the test
Code: Select all  Expand view


#include "fivewin.ch"
#include "Urllink.ch"

REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN




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()

RETURN nil

//----------------------------------------------------------//
Function test()
local oDlg,oFont,oBold
local aGet:=array(10)
local oSay:=array(10)
local oScrollInizio
local bClick //action for urlink
local nRow:= 12
local ncol:= 10

 local cTitle := "Impostazioni visualizzazione"


 bClick := { | o | Locate_Records2(left(o:GetText(),4),2022) }  //Locate_Records(left(o:GetText(),4),2022)

    DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0, 14
    DEFINE FONT oBold NAME "MS Sans Serif" SIZE 0, 12 BOLD
 DEFINE DIALOG  oDlg ;
      SIZE 500, 250  PIXEL TRUEPIXEL RESIZABLE ;
      TITLE cTitle


      @ nRow, ncol Say oSay[1] Prompt "Date predefinite " of oDlg SIZE 200,14 PIXEL  FONT oBold
        nRow+=20
      @ nRow, nCol URLLINK oSay[2]  OF oDlg PIXEL FONT oFont  URL "1871 - Archivio Completo"
      nRow+=20
      @ nRow, nCol URLLINK oSay[3]  OF oDlg PIXEL FONT oFont  URL "1939 - Archivio a 10 Ruote"
      nRow+=20
      @ nRow, nCol URLLINK oSay[4]  OF oDlg PIXEL FONT oFont  URL "1946 - Estrazioni continue"
      nRow+=20
      @ nRow, nCol URLLINK oSay[5]  OF oDlg PIXEL FONT oFont  URL "2005 - Ruota Nazionale"
      nRow+=20
      @ nRow, nCol URLLINK oSay[6]  OF oDlg PIXEL FONT oFont  URL "2005 - Estrazioni trisettimanali"
      nRow+=20
      @ nRow, nCol URLLINK oSay[7]  OF oDlg PIXEL FONT oFont  URL "2009 - Estrazioni Automatizzate"
      nRow+=40
      @ nRow, ncol Say oSay[8] Prompt "Ultime estrazioni " of oDlg SIZE 200,14 PIXEL  FONT oBold
      nRow+=20
   
      For n=2 to 7
          oSay[n]:bAction = bClick
      next










     @ 100,10 BUTTON oBtnConfirm PROMPT "OK" of oDlg  SIZE 80,22 DEFAULT ACTION ( oDlg:end( IDOK  ) )
     @ 100,10 BUTTON oBtnClose PROMPT "Annulla" of oDlg  SIZE 80,22 CANCEL ACTION ( oDlg:end( IDCANCEL ) )

   oDlg:bResized  := <||
        local oRect        := oDlg:GetCliRect()

                oBtnConfirm:nLeft    := oRect:nRight - 200
                oBtnConfirm:nTop     := oRect:nBottom - 25
                oBtnClose:nLeft    := oRect:nRight - 100
                oBtnClose:nTop     := oRect:nBottom - 25

        return nil
        >

 ACTIVATE DIALOG oDlg center

 Return nil



Function Locate_Records(anno1,anno2)
   local aLocate:= {}
   LOCAL nFirst,nLast


   USE LOTTO ALIAS LOTTO

   locate for year(LOTTO->data) = anno2

      if (Found())
         locate for year(LOTTO->data) != anno2 ;
            next 60        // PERCHè LE ESTRAZIONI ERANO 52
      endif



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

      locate for year(LOTTO->data) = VAL(anno1 )

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

      AaDd( aLocate,{nFirst,nLast,anno1, anno2})

      XBROWSER  aLocate
      RETURN NIL


   Function Locate_Records2(anno1,anno2)
   local aLocate:= {}
   LOCAL nFirst,nLast, oDbf


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

   oDbf:Exec( < ||
           locate for year(oDbf:data) = anno2
          return FOUND()
          > )

          if (Found())
      oDbf:Exec( < ||
         locate for year(oDbf:data) != anno2 ;
         next 60        // PERCHè LE ESTRAZIONI ERANO 52
           return FOUND()
          > )

      endif



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

       oDbf:Exec( < ||
      locate for year(oDbf:data) = VAL(anno1 )
         return FOUND()
         > )


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

      AaDd( aLocate,{nFirst,nLast,anno1, anno2})

      XBROWSER  aLocate
      RETURN NIL
 
Last edited by Silvio.Falconi on Mon Apr 18, 2022 8:11 am, edited 1 time in total.
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: Nages Help for locate

Postby Silvio.Falconi » Sun Apr 17, 2022 11:46 pm

Perhaps I found a solution I used oDbf:load() because There is no Method locate() in TDatabase and locate is not buffered



Function Locate_Records3(anno1,anno2,oDbf)
local aLocate:= {}
LOCAL nFirst,nLast

oDbf:use()
select(oDbf:nArea )
oDbf:gotop()


locate for year(FIELD->data) = anno2
oDbf:load()

if (oDbf:Found())
locate for year(FIELD->data) != anno2 ;
next 60 //
endif

oDbf:load()

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

locate for year(FIELD->data) = VAL(anno1 )
oDbf:load()

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


AaDd( aLocate,{nFirst,nLast,anno1, anno2})

XBROWSER aLocate
return nil

It seem run ok , I not Know if it is right
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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