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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separating data within a field (ie. Johnson,Emily) 1

Status
Not open for further replies.

roisinmck

Technical User
May 11, 2006
4
US

I am using foxpro.

I have a name field with both first and last name. As noted above Johnson,Emily.

How do I separate and put into different fields?
 


[tt]
a = 'Johnson,Emily'
surname = ATXLEFT(a, ',') {See faq184-5975}
givenname = ATXRIGHT(a,',')
[/tt]


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 

Hi Roisinmck,

Welcome to the forum.

Mmerlinn has given you one possible answer. But there are many ways to do what you want. Here's my suggestion:

Code:
x = "Johnson, Emily"
lastname = GETWORDNUM(x, 1, ",")
firstname = GETWORDNUM(x, 2, ",")

By the way, with any problem of this type, be sure to think about the special cases. For example, what happens if a firstname is missing or if there are two commas.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks much for the reply. How do I get the separated first and last name to populate new columns. The following is not working? as I get the same first name and last name in all records?

USE C:\MAILFILE.DBF IN 0 EXCLUSIVE
X = FLNAME
SURNAME = GETWORDNUM (X, 1, ",")
FIRSTNAME = GETWORDNUM (X, 2, ",")

REPLACE ALL SURNAME1 WITH SURNAME
REPLACE ALL FIRSTNAME1 WITH
 
This should work, although I didn't test it to be sure.

USE C:\MAILFILE.DBF IN 0 EXCLUSIVE

REPLACE ALL SURNAME1 WITH GETWORDNUM (FLNAME, 1, ",")
REPLACE ALL FIRSTNAME1 WITH GETWORDNUM (FLNAME, 2, ",")


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
LOL.

I just tried testing it and it failed because the function GETWORDNUM() does not exist in FP2.6.

Guess that is why I must have written the ATXLEFT() & ATXRIGHT() UDFs in the first place.

Since I can't test GETWORDNUM() here I don't know what it does in special cases. However, my UDFs do not crash if either name is missing. They just return an empty string (""). With double commas they will return wrong results though, but they still won't crash.




mmerlinn

"Political correctness is the BADGE of a COWARD!"

 

However, before that, it was available in foxtools.fll.

I checked FP2.6 books that came with FP2.6 and don't find any mention of this being available. I also checked VFP3.0, and it is available there. Based on what I read in the VFP3.0 manuals, it appears that it was introduced in VFP but never available in FP.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Thanks so much for the help!! This forum is great.
 

Mmerlinn,

I checked FP2.6 books that came with FP2.6 and don't find any mention of this being available.

Sorry, I forgot to mention ... in Foxtools, the functions were named WordNum and Words respectively.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 


MikeLewis

Not sure I was clear. I found no mention of FoxTools in any of the original documentation I have for FP2.6. But I did find it in the documentation for VFP3.0. But that is all that I found. No mention of what FoxTools contains, nor how to use FoxTools.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Foxtools was shipped with FP 2.5 and later. You should find it in your main FP directory along with a text file descibing the various functions and their parameters. In order to use it you need to issue the following:
Code:
SET LIBRARY TO FoxTools
Then you can issue do commands to access the various procedures.

Regards,
Jim
 

I don't know about VFP 3, but in recent versions, there is a separate help file for Foxtools. It should be in your main VFP directory. For VFP 9, it is called FOXTOOLS.CHM, but for earlier version it might be FOXTOOLS.HLP.

Although most of the function are now redundant, it's worth glancing at this help file because there are still one or two useful items there.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I did a disk search and found the Foxtools read me folder, but nothing else. Obviously, FP2.6 came with Foxtools, but for some reason was either never loaded when FP was installed, or was removed for some reason.

I will check my main developement machine later and see if I find it there.

Also will look over what is available in Foxtools and see if I should make sure it is available for use.

Are all versions of Foxtools the same for FP2.5 and FP2.6? I have several copies of various versions of both FP2.5 & FP2.6 (as well as VFP3.0) and would need to know if Foxtools is specific for each version, or can I just grab one and upload it to all three machines?


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top