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

VFP6 adding a ' to any chr field starting with a '+'.

Status
Not open for further replies.

wetton

Technical User
Jun 26, 2006
42
0
0
AU
I need to scan through a table and add a ' to any chr field starting with a '+'.

Any help with some code please.

Thanks


PW
 
may be not very effective, but just works.
Works on a current table.
WARNING! some data could be lost by doing PADR (last character)

Code:
clear
n= afields(fieldInfo)
for i=1 to n	
	? fieldInfo(i,1),  fieldInfo(i,2), (fieldInfo(i,2)="C"), fieldInfo(i,3)
	if fieldInfo(i,2)="C"
		fildname = fieldInfo(i,1)
		fildsize = fieldInfo(i,3)
		replace &fildname. with padr("'"+&fildname., fildsize) for &fildname.="+"
	endif
next
?"Over!"
 
Do you need the ' added to the beginning or the end of the field - if it's the end, do you need it trimmed first (or just the last character replaced)?

Are you concerned that the fields might 'overflow?

Code:
private myFields,myFieldname,i
use mytable
myFields = afields(myArray)
for i = 1 to myFields
	myFieldname = myArray(i,1)
	if myArray(i,2) = "C"
		replace all &myFieldname. with trim(&myFieldname.)+"'" for left(&myFieldname.,1) = "+"
	endif
next

Regards

Griff
Keep [Smile]ing
 
Tsh,

If you take what we just did, and then look at the SCO-IBM lawsuit, you can see why they're in a bit of a mess!

Two people working completely indpendently, come up with almost identical code for the same problem...

B-)

Regards

Griff
Keep [Smile]ing
 
Griff,
I would like to think
"Great minds work alike" ;))
 
Thanks to you both...

Testing in my app now..


PW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top