Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Relation
Message
From
15/05/2007 10:20:13
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
01225516
Message ID:
01225544
Views:
30
>In my applications that are already running for long time
>and would be hard to modify, I am considering to use the code below
>
>A random number would be added to the code to prevent duplications
>
>Do you think 1 in 10,000 is good a range to prevent duplications ?
>
>**************************************
>add_code = Int(10000*Rand())
>
>dimension lctemp[1]
>select max(ap.id2) from ap ;
> into array lctemp
> lcTemp[1] = nvl(lcTemp[1],0)+1 + add_code
>replace ap.id2 with lctemp
>
>*********************************************

You can never trust a random number. Instead you add a line to see whether the random number is used before or not. Something like
Do while .T.
  add_code = Int(10000*Rand())
  Select yourfield from yourtable where yourfield=add_code into array dummy
  If _tally=0
    exit
  endif
Enddo
But, as also others have written, the best and ONLY really reliable solution is to use a separate table for the invoice numbers.
Previous
Reply
Map
View

Click here to load this message in the networking platform