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
#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
//---------------------------------------------------------//