Create unique ID's in VFP

I need to create unique record id's in VFP based on mailing information: zip5, address, lastname, firstname. Once created, relational tables will be loaded in SQL server 7 with the unique ID's. Any suggestinos?

-------------Problems Reply------------

You can use a GUID: GUID entry at FoxPro Wiki.

And here are some examples.

Easiest one using WSH...

* VFP 7+
oGUID = CreateObject("scriptlet.typelib")
cGUID = Strextract(oGUID.GUID, "{", "}" )

* Other VFP
oGUID = CreateObject("scriptlet.typelib")
cGUID = substr( oGUID.GUID, 2, 36 )

VFP does have support for unique IDs - in that it has Primary Indexes (which can be based on multiple fields - but make sure the key length is fixed, so if your VFP table uses varchars you will need to pad the fields) and a table can also have Candidate Indexes (where the indexed field(s) must be unique, just like a primary key, but you can have multiple candidate indexes per table).

Either of these will enforce uniqueness in your fields, but generating a primary key based on zip5, address, lastname and firstname will be inefficient. The suggestion of GUIDs will work nicely, or if you have VFP8 or later you can use an Autoinc column, which is analogous to an Identity column in SQL Server.

Incidentally, unique indexes are only used for backward compatibility..

I created my own function for that purpose to return a unique identifier. When I have a new record I just scan the database and have the function replace the unique identifier field (I call mine UID) in the database with a new uid if the record does not have one.

FUNCTION UIDgenerator()
LOCAL c_dump

c_UID = STRTRAN(SYS(2015),"_","") + [-]

c_dump = STRTRAN(SYS(2015),"_","")
c_dump = STRTRAN(SYS(2015),"_","")
c_dump = STRTRAN(SYS(2015),"_","")

c_UID = c_UID + STRTRAN(SYS(2015),"_","")


endfunction() &&UIDGenerator

You don't have to do c_dump 3 times, but I wanted the identifiers to be a little more further apart.

Category:uniqueidentifier Views:1 Time:2009-02-18

Related post

  • How do I create unique IDs, like YouTube? 2009-07-02

    I've always wondered how and why they do example: How are these IDs generated such that there are no duplicates, and what advantage does this have over having a simple auto incrementing numeric ID? How

  • how to create unique keyword in the oracle db? 2010-04-14

    i am using autocomplete with oracle Db,how to create unique keyword for the table. KEYWORD VARCHAR2(100) COUNT NUMBER(18) how can i make as unique can plz tell the query --------------Solutions------------- ALTER TABLE mytable add CONSTRAINT keyword_

  • Is it possible to design our own algorithm to create unique GUIDs? 2010-05-04

    GUID are generated by the combination of numbers and characters with a hyphen. eg) {7B156C47-05BC-4eb9-900E-89966AD1430D} In Visual studio, we have the 'Create GUID' tool to create it. I hope the same can be created programmatically through window AP

  • Which kind of user's information I can use for create unique user's key? 2010-08-20

    I've next problem: I need create unique user key based on user's information what I can receive from user's request to my web-page (ASP.NET). I'll use this key for auto-login functionality (I know about cookie ^^) What kind of information I can use?

  • Need to create unique image selectable function in jquery 2010-08-30

    I have try with toggle function in jquyer but its not working for multiple LI and I tried with the selectable function not working. Need to create unique image selectable function in jquery. I have many li with inside image on click on image li will

  • creating unique user web page 2010-09-09

    I want a customized home page for each user of my site. I was thinking it might be best to have a master page with place holders (for name, default image, etc) and have the site pull the data from the db on page load. Is this better than storing the

  • CANNOT create unique index in SQL Server, how to know what index is the index ID referring to 2010-09-22

    I have a script that gives an error when being executed: Msg 1505, Level 16, State 1, Server CBR07I300FVA1, Line 1 CREATE UNIQUE INDEX terminated because a duplicate key was found for index ID 17. Most significant primary key is '44'. The statement h

  • Creating unique random numbers 2010-12-10

    I have created the following method so as to create unique random numbers . (This unique values belong to the nodes of a tree): static Random rand = new Random(); public static ArrayList<Node> go(int n) { ArrayList<Node> list = new ArrayL

  • Creating unique URL/address for a resource to share - Best practices 2011-01-09

    In my application there is a need to create unique URLs (one per resource) that can be shared. Something like Google Calendar Private address for a calendar. I want to know what are the best practices for this. If it helps my application is in Django

  • Creating Unique URI Slugs - is this a Recursive Trigger? (SQL Server) 2011-01-13

    Here's my table: dbo.Posts PostId (IDENTITY, PK) Subject UniqueUri (NVARCHAR(350), NOT NULL) When i create a "Post", i insert a blank UniqueUri (using the NEWID() built-in function). I then have a trigger on the "Post" table: CREATE TRIGGER [dbo].[On

  • Could not create unique index - claims to have duplicate values but it doesn't 2011-01-18

    I'm trying to create a unique index on code field: $ CREATE UNIQUE INDEX "one_code_per_person" on "core_person"("code") WHERE "code" IS NOT NULL; ERROR: could not create unique index "one_code_per_person" DETAIL: Table contains duplicated values. It

  • Why do we have to create unique uuid for every interface in a idl? 2011-02-24

    Why do we have to create unique uuid for each interface in a idl ? For example in this interface there's a unique uuid for every interface in TradingLib. import "oaidl.idl"; [uuid(7C948DDC-8C22-46CF-91AD-1E043A0E1A10), object] interface IInventory :

  • Creating unique hash code (string) in SQL Server from a combination of two or more columns (of different data types) 2011-03-01

    I would like to create unique string columns (32 characters in length) from combination of columns with different data types in SQL Server 2005. --------------Solutions------------- I have found out the solution elsewhere in StackOverflow SELECT SUBS

  • Create Unique Image Names 2011-03-18

    What's a good way to create a unique name for an image that my user is uploading? I don't want to have any duplicates so something like MD5($filename) isn't suitable. Any ideas? --------------Solutions------------- as it was mentioned, i think that b

  • Create unique constraint with nvl in Oracle 2011-06-16

    How can I create unique constraint when I need to treat null values as equals. For alter table T1 add constraint T1_UN unique (nvl(C1, ' ')) i get ORA-00904: : invalid identifier points on nvl Thanks! --------------Solutions------------- NOT NULL see

  • XML to XML - Create Unique IDs and reference them in the same document 2011-07-07

    I have a source xml that contains the addresses in spot and need to transform into an xml that holds all addresses into a single element and references each one. I am using Saxon 9.1 processor and stylesheet version 1.0. Thank you for helping. Source

  • How to create unique key names in google app engine 2011-07-18

    I'm having trouble figuring out how to create unique key names for my online election app. Here is a typical set of relevant entities: 1 Election 5 Candidates 100,000 Voters up to 100,000 Votes I need a unique key name for each Voter entity for the r

  • will_paginate 2.3.15 - creating unique id selector for each page link 2011-08-17

    Using the will_paginate gem, I want to create output that looks like this for the <a> tags: <div class="navPagination"> <span class="disabled prev_page">Prev</span> <span class="current">1</span> <a id="pag-top-

  • PHP/MySQL - Best way to create unique random string? 2011-10-25

    How do I create a random unique string in MySQL? when I need to create a random string in PHP I use this function: public function generateString($length) { $charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for($i=0; $i<

Copyright (C), All Rights Reserved.

processed in 0.135 (s). 11 q(s)