Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Key generator, not returning correct value - first time call
Message
De
31/01/2001 09:43:31
Gene Maddox
Silver Creek Technologies
Johnson City, Tennessie, États-Unis
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Key generator, not returning correct value - first time call
Divers
Thread ID:
00470598
Message ID:
00470598
Vues:
66
hello all. i have a very frustrating problem. i have written a function to return the next proper key in a table. the setup is simple. there is a table that contains the name of the tables used in the project and the last key value used for that table. example table - tickets keyval - 2000. basically there is a procedure that scans through a file and appends records to the ticket table. inside the scan is something like this.
select out
scan
    nkey = GenerateKeyValue('tkt')
    select tkt
    append blank
    replace tkt_pk with nkey
    select out
endscan

the first call to the GenerateKeyValue function is returning the wrong value. it is returning 2000 when it needs to return 2001. after the first call it works fine. there are some other places in the project where off the wall values are returned that aren't even in the key value table. below is the GenerateKeyValue function. any help is appreciated. thank you very much!

*===================================================================
function GenerateKeyValue
lparameter cKeyFile
*===================================================================

 if parameters() = 0 or empty(cKeyFile)
   messagebox("Failure in Primary Key Generation. " + chr(13) + ;
	"Introducing Error to Halt Execution. " + chr(13) + ;
	"Call *****.")
	set step on
 endif

* Declare local variables:
 local yCurArea   && Current work area upon entry
 local yCurRepro  && Setting of 'reprocess' upon entry
 local lGotIt 	 && Record lock successful
 local tStart	 && Starting number of seconds
	 
* Save the current work area:
 yCurArea = select()

* Initialize the values table:
 select 0
 if not used('rx23')
    use gAdvDir + "\arm\dat\rx23"
 endif

 select rx23

 set order to spc in rx23

* Locate the specified value record:
 if not seek( padr( cKeyFile, 5 ))

    * Record not found; create it:
    insert into rx23 values( padr(alltr(cKeyFile),5), 0, 1, 0, 0 )
 
 endif

* Calculate the generated number:
 tStart = seconds()
 
 do while not lGotIt
    if rlock()
	replace rx23.ia with iif( ;
	   ( ( rx23.ia + rx23.ib ) > rx23.ic ) and ( rx23.ic <> 0 ), ;
	   rx23.id + rx23.ib, ;
	   rx23.ia + rx23.ib )
	lGotIt = .T.
	unlock
    else
	if (seconds() - tStart) > 20 then
	    messagebox("Failure in Primary Key Generation. " + chr(13) + ;
			"Introducing Error to Halt Execution. " + chr(13) + ;
			"Call *****.")
	    set step on
	endif
    endif
		
 enddo

* Clean up:
 select (yCurArea)

* Return the generated value:
 return rx23.ia
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform