Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique number
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00113894
Message ID:
00113910
Vues:
20
Dan,

The most reliable way to do this is to have a table with one record for each number you want to generate. So if you need invoice numbers and customer numbers the table would have two records. Each records has two fields, "type" and "LastUsed." You can write a function to return a unique number that looks something like this:
FUNCTION GetNo
LPARAMETERS cType

IF !USED('numlist')
  USE numlist IN 0
ENDIF
SELECT numlist
LOCATE FOR numlist.Type=m.cType

DO WHILE !RLOCK()
ENDDO

m.nNextNum=numlist.LastUsed+1
REPLACE numlist.LastUsed WITH m.nNextNum
UNLOCK

RETURN m.nNextNum
It's important that you get the lock before you increment the number. This will prevent another user from incrementing it at the same time and getting the same number. You'll probably also want to make sure that you change the work area back to the one in effect before the function was called.

>Does anyone have a way of creating a truly, truly unique number to use as an identification for a record in Foxpro 2.6a? We have several people writing to a dbf and when they create a record in the dbf it puts a unique (or so we thought using sys(3)) number in a field. We are running these programs on P6-300's. We have also tried val(sys(3))+recno number of file+1. This also has not proved to be unique. Can anyone help us???
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform