July 7, 200322 yr I Nedd a script that will allow me to assign a unique number to a record from a pool of numbers, let
July 8, 200322 yr How about this? The field "pool" is text and global. This is your pool of available numbers ("1 2 3 4 5") You create two simple scripts for 'NewRecordScript' and 'DeleteRecordScript'. NewRecordScript creates a new record. Then sets field "id" to leftwords(pool,1) - The next available from the pool. Then sets field "pool" to rightwords(pool,wordcount(pool)-1) - Taking away the used left ID - DeleteRecordScript first sets field "pool" to pool & " " & id - Making the number available again Then deletes the record. - Check the attached file if you like
July 9, 200322 yr This is okay if it doesn't matter in what order you assign the numbers. Since you may delete record 5 then 2 then 3, these numbers will be appended back onto the list in that order and will be re-assigned in that order. If you want to always assign the lowest available number, then you will have to add a bit more to the script to keep things sorted. Another option is to use a separate file with one record for each number in the pool with a field containing the number, and a field called "available". Set this field to 1 when the number is available, and clear it when the number is assigned. You can then set up a constant relationship "PoolAvailable" from a global = 1 in the main file to the available field in the pool file. Also create a relationship "Pool" from the main file to the pool file based on the number field in each. To assign a number, run this script in the main file Set Field [iDnumber,PoolAvailable::IDnumber] Set Field [Pool::Available, ""] To delete the record and return the number to the pool run this script: Set Field [Pool::Available,1] Delete Record See the attachment. Pool-o-numbers.zip
Create an account or sign in to comment