Generate a 4-digit Unique Number In a List

Build your list of AccuZIP6 commands by requesting commands and sharing commands with other users

Moderators: Chrissy, Steve, Terry, Donna, Dave, Eric, MartyH, Kristen, Geoff, Vince

Post Reply
User avatar
Terry
Site Admin
Posts: 1983
Joined: Wed Sep 20, 2006 3:45 pm

Generate a 4-digit Unique Number In a List

Post by Terry » Fri Mar 29, 2013 9:34 am

The command syntax below will generate what appears to be a random 4-digit number in a field called "record" in your list. If your database has less than 10,000 names, this will create 0001-9999 in the database, with no value appearing twice. In reality it's simply indexing it on the "First" field, then assigning the record number based on that. Then it will re-index on zip, so that the number appears to be random.

If you wish to index on a different field, simply change the reference to "first" to your desired field name. As with all commands, click on Edit>Fields and then use the syntax below in the Syntax box.

Code: Select all

SET SAFETY OFF
ON ERROR com_message=message()
index on ALLT(first) tag mytag
copy to "C:\temp.dbf"
ZAP
APPEND FROM C:\temp.dbf
ALTER TABLE ALIAS() ADD COLUMN record C(4)
REPLACE ALL RECORD WITH PADL(ALLT(STR(RECNO())),4,"0")
index on ALLT(zip) tag myzip
copy to C:\temp.dbf
ZAP
APPEND FROM C:\temp.dbf
DELETE C:\temp.dbf

Post Reply