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!

Change name format with comma 1

Status
Not open for further replies.

TheLazyPig

Programmer
Sep 26, 2019
101
PH
Hi!

How can I change Lastname;Firstname;mi to Lastname, Firstname mi?


Thanks in advance.
 
here are a couple of different approaches

Code:
m.lcMyString = "Lastname;Firstname;mi"
m.lcNewString = STRTRAN(strtran(m.lcMyString,";",",",1,1),";"," ")

or

Code:
m.lcMyString = "Lastname;Firstname;mi"
m.lcLastname = getwordnum(m.lcmystring,1,";")
m.lcFirstname = getwordnum(m.lcmystring,2,";")
m.lcMI = getwordnum(m.lcmystring,3,";")
m.lcNewString = alltrim(m.lcLastname)+", "+alltrim(m.lcFirstname)+" "+alltrim(m.lcMi)


hth
n
 
Looks like a line of CSV data, just with the semicolon instead of the comma as separator.

I'd read that in with IMPORT or APPEND FROM and then you can build output with the single fields you have as you like.


Chriss
 
I forgot to add that the tables I used for getting names is from an oracle db. It doesn't work.
 
In what way doesn't it work? Do you mean that you ca't access the Oracle tables from within VFP? Or that you can access the data but for some reason Nigel's code doesn't do what you want? And, if the latter, what exactly happens? Do you get an error message, or what?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There's no error. When I open the extracted xls file the column for name does not appear.
 
Perhaps one of the other forum regulars will be able to answer this question, but I am afraid it is beyond my abilities. I have no idea how you are connecting to Oracle, what method you are using to extract data from it, or how you are attempting to access or view the Name column. I also don't know where the XLS file comes into the picture.

If the problem is related to your requirement to change a semi-colon in the Name to a comma, perhaps someone here can help. If it is not, your best bet would be to start a new thread, give it a title that reflects the nature of the problem, and - above all - explain the problem clearly and competely.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Querying oracle via an ODBC driver should give you a cursor, not an XLS, what are you doing to create an XLS?

1. You need a 32bit ODBC driver working for the Oracle database version
2. For ease of the VFP code create an ODBC DSN with the 32bit ODBC manager (which is in the Windows\SysWow64 folder) - ensure the test connection works and call the DSN "Oracle".
3. Us something like this in VFP

Code:
handle = SQLConnect("Oracle")
If handle<0
   AErrorr(larror)
   ? 'Error: '+ laError(2)
Else
   If SQLExec(hande,'SELECT * FROM table','Result')>0 && whatever Oracle query you need
      Select Result
      Browse
   Endif
Endif

That should give you either an error with more information of what goes wrong or the result in a cursor named Result and with captions.

I guess you're actually already there, but then copy that to an XLS and, in the worst case, VFP creates a CSV without captions, just pure data.
But whenever you query a remote database the first level of result inside VFP will be a cursor and that will have columns and column names.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top