>how can i do this check and see that the name entered is already in the archive?
I have the primary keys, the customer database is indexed on name, surname, city, province and region.
the primary key that was there before, ie "0001" four characters, I have hurt to remove it due to the countless problems both with tdatabase and with tdata.
Yes, I know you and nages gave me many examples last year but then on the net all this becomes very difficult.
Before I had found an expedient that is to save the surname and name (full name field) in a single field and do the index and check on this field but I wanted to know if there was an alternative.
In the program I often have families that have the same surname and often also the name, for example my name is like my grandfather.
the customer database is indexed on name, surname, city, province and region
local oDbf
local cName := "David"
local cLast := "Jochum"
oDbf := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
if oDbf:LookUp( UPPER( PADR( cName, 20 ) + PADR( cLast, 20 ) ), ;
"UPPER(FIRST+LAST)", { || FOUND() } )
? "Found"
else
? "Not Found"
endif
oDbf:Close()
nageswaragunupudi wrote:Mr. Silvio
Without any special index:
- Code: Select all Expand view RUN
local oDbf
local cName := "David"
local cLast := "Jochum"
oDbf := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
if oDbf:LookUp( UPPER( PADR( cName, 20 ) + PADR( cLast, 20 ) ), ;
"UPPER(FIRST+LAST)", { || FOUND() } )
? "Found"
else
? "Not Found"
endif
oDbf:Close()
Note: 20 and 20 in PADR() function are the field sizes of FIRST and LAST.
@ 12, 10 SAY "Cognome:" OF oDlg SIZE 31, 8 PIXEL FONT oFont
@ 10, 67 GET aGet[1] VAR oCliente:Clicognome OF oDlg SIZE 100, 12 PIXEL FONT oFont
@ 26, 10 SAY "Nome :" OF oDlg SIZE 22, 8 PIXEL FONT oFont
@ 24, 67 GET aGet[2] VAR oCliente:Clinome OF oDlg SIZE 100, 12 PIXEL FONT oFont ;
VALID SearchCli( oCliente:Clicognome, aGet[2], 1,oDbf,oCliente:Clinome )
function SearchCli ( cCognome, oGet, nMode,oDbf,cNome )
local lreturn := .f.
local nRecno := oDbf:RecNo()
local nOrder := oDbf:OrdNumber()
local nArea := Select()
if Empty( cNome )
if nMode == 4
return .t.
else
MsgStop("E' obbligatorio questo campo.")
return .f.
endif
endif
oDbf:SetOrder( 1 ) //CLICOGNOME
oDbf:GoTop()
IF oDbf:LookUp( UPPER( PADR( cCognome, 20 ) + PADR( cNome, 20 ) ), ;
"UPPER(CLICOGNOME+CLINOME)", { || FOUND() } )
DO CASE
Case nMode == 1 .OR. nMode == 3 // new or duplicate
lreturn := .f.
MsgStop("Nominativo esistente.")
Case nMode == 2 // modify
if oDbf:Recno() == nRecno
lreturn := .t.
else
lreturn := .f.
MsgStop("Nominativo esistente.")
endif
Case nMode == 4 //selection dialog
lreturn := .t.
END CASE
ELSE
if nMode < 4
lreturn := .t.
else
if MsgYesNo("Nominativo inesistente. ¿ Desideri inserirlo ora? ") // on selection dialog ask to add the new record
lreturn := ClEdita( , 1, , , @cCognome )
else
lreturn := .f.
endif
endif
endif
if lreturn == .f.
oGet:cText( space(20) )
endif
oDbf:SetOrder( nOrder )
oDbf:GoTo( nRecno )
Select (nArea)
return lreturn
Application
===========
Path and name: C:\Work\Prg\Prenotazioni\WinBeach.Exe (32 bits)
Size: 7,603,200 bytes
Compiler version: Harbour 3.2.0dev (r1904111533)
FiveWin version: FWH 21.04
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 29 secs
Error occurred at: 14-06-2021, 23:29:13
Error description: Error BASE/1066 Parametro errato: condizionale
Args:
[ 1] = U
Stack Calls
===========
Called from: source\Clienti\PClienti.prg => CLCLAVE( 777 )
Called from: source\Clienti\PClienti.prg => (b)CLEDITA( 597 )
Called from: .\source\classes\TGET.PRG => TGET:LVALID( 2282 )
Called from: .\source\classes\CONTROL.PRG => TGET:FWLOSTFOCUS( 1205 )
Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1802 )
Called from: .\source\classes\TGET.PRG => TGET:HANDLEEVENT( 1279 )
Called from: .\source\classes\WINDOW.PRG => _FWH( 3560 )
Called from: => DIALOGBOXINDIRECT( 0 )
James Bott wrote:The field sizes for LAST and FIRST in the sample database you sent me are both 18 characters not 20. You had better check yours.
Your GETs should be using the current field size, so you shouldn't need to pad them unless you are looking them up in a different file, then you need to use the field size of that file (or make the fields in that file the same length). In fact field sizes should always be made the same in each file that is using the same name fields.
These are all problems that unique primary key IDs would solve.
James
James Bott wrote:Silvio,
Hmm, I see that my version of TDatabase does not have a Lookup() method. And Nages didn't provide the Found() function. So you are dead in the water until you have those. Does your version of TDatabase have the Lookup() method?
Perhaps you can just use the Seek() method?
James
nageswaragunupudi wrote:1) The function FOUND() is a native Clipper/Harbour RDD function and has been there from the time Clipper was born.
2) Method LookUp(...) was first introduced in Sep 2017 version and exists in FWH1805.
local cNomeIntero :=alltrim(cFirst) +alltrim(cLast)
oDbf:SetOrder( 16 ) //first+last
oDbf:GoTop()
oDbf:Seek( UPPER( cNomeIntero ) )
xbrowser oDbf
not good it go to eof of dbf and give me not return if found the record
1) The function FOUND() is a native Clipper/Harbour RDD function and has been there from the time Clipper was born.
2) Method LookUp(...) was first introduced in Sep 2017 version and exists in FWH1805
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Rick Lipkin and 43 guests