Information générale
Catégorie:
Codage, syntaxe et commandes
>>>Let's face it. NO system is 100% foolproof. That's why I check for existing values & trap errors.
>>
>>I thought that VFP already had a SYS function that returned a ten-character unique ID based on the time. From help, SYS(2015):
>>
>>Returns a unique 10-character procedure name that begins with an underscore followed by a combination of letters and numbers.
>>
>>Syntax
>>
>>SYS(2015)
>>
>>Returns
>>
>>Character
>>
>>Remarks
>>
>>SYS(2015) can be used to create unique procedure or function names.
>>
>>The name that SYS(2015) returns is created from the system date and system time. Calling SYS(2015) more than once during the same millisecond interval will return a unique character string.
>>
>>This function has worked wonderfully for me for generating unique values for key fields and the like.
>
>
>I made my function after Friday's conference where Pium was very dis-satidfied with SYS(3). Seems like he was having problems with system generated IDs. So this sparked a nice little debate after which, in a true programmer style (s), rolled up my sleeves and created my own....
>
>My little experiment sparked a number of good responses. Bottom line of all the responses is nothing is perfect. No matter what method you use to create a unique ID, it seems to boil down to checking for an existing value when you create a new ID and/or trap the error if a uniquevalue is violated.
>
>Thanks
>Tom
I'am using sys(2015) as well in my unique indexes
i always call the record_key forceing uniqeness by the on error like this
CASE tnErrornr = 1884
* Uniqueness of index is violated
IF 'RECORD_KEY' $ lcAdditext
* The default key generated by the system was already in the system
* because this is a sys(2015) we can have the system do it again without getting into a endless loop.
lnMessans = IDRETRY
ELSE
lcMessage = ERR_1884 && Error text 1884
lnIcon = MB_ICONINFORMATION && Icon stop
lnButtons = MB_OK && Ok button only
ENDIF
I hope this is a nice sugesstion for anyone.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement