Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Key generator, not returning correct value - first time
Message
De
31/01/2001 10:55:30
 
 
À
31/01/2001 10:46:10
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00470598
Message ID:
00470659
Vues:
41
One other thought I should have added is to step through the code in the Debugger to see how the code is executing.

>I'm not sure why you are using such a roundabout way to get the next key, but I assume you have reasons for the methodology.
>
>I few observations:
>
>1) I would use SELECT(0) to get the current work area to avoid COMPATIBILITY problems
>2) I would init local variables (eg. lGotIt ) even though VFP inits them to .F.
>3) I would do something like:
>MyFile= gAdvDir + "\arm\dat\rx23"
>USE (MyFile) IN 0 ORDER spc ALIAS rx23
>SELECT rx23
>
>4)But a real problem is that you unlock the record before returning the value in the table. Though not likely, in the intervening time, another hit could change the value. After incrementing the value I would store it to a local variable, unlock the record, and return the local variable value.
>
>Ohters may have some other relevant observations to help you.
>
>Bill
>
>
>>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
>>
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform