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

VFP6 - strtran() on form field 1

Status
Not open for further replies.

wetton

Technical User
Jun 26, 2006
42
AU
I am outputting collected data to both a csv file and a dbf.

Some of the fields can have a minus or double minus ( - or -- )at the front of a string.

To allow these to show correctly in Excel I have added a "'" to the front of the string.

I wish to remove these when they appear in the field of a form.

I tried a strtran in the rowsource but that is not allowed.


How can I do this?

Thanks
PW
 
Don't put the single quote in the DBF?

Instead of STRTRAN:
Code:
    REPLACE ALL myField WITH CHRTRAN(myField, ['], [])

Removing only the 1st character if needed would be cleanest:
Code:
    REPLACE ALL myField WITH IIF(LEFT(myField,1)=['],RIGHT(myField,LEN(myField)-1),myField)


If you must leave them, then another way would be to create another DBF/cursor without them.

Code:
lcTable= [C:\MyPath\MyTable.dbf]


lcCmd = []
USE (lcTable)

FOR lnField = 1 TO AFIELDS(laField)
	lcField = laField(lnField, 1)
	lcDataType = laField(lnField, 2)
	lcLen = TRANSFORM(laField(lnField, 3))
	
	IF lcDataType = [C]
		lcCmd = lcCmd + [, IIF(LEFT(&lcField,1)="'",RIGHT(&lcField,&lcLen-1),&lcField) as &lcField]
	ELSE 
		lcCmd = lcCmd + [, &lcField]	
	ENDIF 
ENDFOR 

lcCmd=RIGHT(lcCmd,LEN(lcCmd)-1)

SELECT (JUSTSTEM(lcTable))
BROWSE NOWAIT 

SELECT  &lcCmd FROM (lcTable) INTO CURSOR ([cur]+JUSTSTEM(lcTable))
BROWSE NOWAIT

Brian
 
If you simply save your stuff to a DBF and then export to an XLS, you go ignore the middle step of creating a CSV. This way you can ignore the quote-to-start.

Ken
 
Actually, I've found a DIF file to be one of the most format friendly stock exports.

I also offer faq184-4704 Export a Formatted Table to Excel using HTML as an example of exporting to Excel with formatting without needing automation.

Brian
 
I now have a need to add a "'" to any fields starting with a '+' chr.

I've tried modifying Brian's code for all fields but have failed.

Anyone help?

Thanks PW
 
Have you put the " in between ' so it would look like:

+'"'

That should work.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks Scott,

Instead of removing a ' I need to add one to any chr field starting with a '+'.

Help with modifying the code would be appreciated.

Thanks

PW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top