Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alphanumeric Identifier

Status
Not open for further replies.

stathread

Programmer
Jan 17, 2006
38
US
Is there a way to add a alphanumeric identifier to a dbf via foxpro? 5 digits?

Thanks
 
Are you talking about renaming the file to a 5-digit number such as 12345.dbf or are you talking about specifying an alias while the table is in use?

A table can be named with all digits, but there is at least one issue that arises if the table name starts with a digit. A table alias cannot open with a digit as the first alphanumeric, so if you open the table without specifiying an alias, then VFP picks one for you. If you open "12345.dbf" in work area 1, then the alias will be "A". If you open "12345.dbf" in work area 20, then the alias will be "W20".

dbMark
 
no im talking about adding a field and appending a unique alphanumeric identifier to each record.

FIELDALPHANUMERIC
a8sa7
df989
ds983
fd9f8
 

Stathread,

Yes, this is possible. But it's not clear exactly what you need to know. Are you asking how to add a new field to an existing table? Or how to store a value in that field? Or what?

Also, do you want to do this programmatically or interactively?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I am sorry i didnt know i had to fully explain since we are in a general foxpro coding forum.

I have a DBF file.

I have 1 field which is empty for all records, lets call this field ALPHANUM.

I would like to run a .PRG or just execute some code via the console which will append a DISTINCT Alpha numeric number in the ALPHANUM field.

I can do this in SQL but im not good with Foxpro. I check for duplicate alphanumeric numbers.

Thank you for your help.
 
I would like to run a .PRG or just execute some code via the console which will append a DISTINCT Alpha numeric number in the ALPHANUM field.

Three lines of code in Fox:
Code:
lcAlphaNum=SYS(2015)             && Get a unique id
APPEND BLANK                     && Add a new record
REPLACE alphanum WITH lcAlphaNum IN MyTable

You say that you know SQL. Do you realise that Fox runs SQL commands natively. You could say:

Code:
lcAlphaNum=SYS(2015)             && Get a unique id
INSERT INTO MyTable (alphanum) VALUES (lcAlphaNum)

Geoff Franklin
 

Stathread,

You wrote:

i didnt know i had to fully explain since we are in a general foxpro coding forum.

Unfortunately, it is difficult for us to give a helpful answer unless you state your problem clearly. I appreciate the problem might seem obvious to you, but if you look back over your original post, you will realise that it's impossible to guess from that exactly what you were trying to achieve.

Anyway, Geoff has now given you a good solution.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
If you're going to use sys(2015), you might want to remove the leading underscore it always provides.

REPLACE ALL (fieldname) WITH SUBSTR(SYS(2015),1)

Note that uniqueness is guaranteed WITHIN A SINGLE FOXPRO SESSION ONLY. If you'll later be adding records, you must manage the uniqueness yourself.

I'm curious, though, whether you might also have some sort of pattern in mind for this alpha-numeric. That is usually the case with this sort of request.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top