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

Convert String to Variables

Status
Not open for further replies.

kamweng

Programmer
Jan 20, 2012
36
MY
I would be grateful if you could help me to convert String to variables.
For example:

ABCD = 1234
XX = 'AB'
YY = 'CD'
XXYY = XX+YY
? XXYY

Is there a way to obtain the result as 1234 and not as 'ABCD'.
Any helps or hints will be valued.
 
Code:
ABCD = 1234
XX = 'AB'
YY = 'CD'
XXYY = XX+YY
? &xxyy
? evaluate(xxyy)
? evaluate("abcd")

Should result in

1234
1234
1234


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
While that works, I think your example is not really covering your needs. If you want to convert any A to 1, B to 2 etc. then what you rather need would be

chrtran(xxyy,"ABCD","1234")

And if you then need the numeric value Evaluate(chrtran(xxyy,"ABCD","1234"))

The example only works with xxyy="abcd", as there is a variable called abcd, it won't work with any other combination of the letters.

Bye, Olaf.
 
Kamweng,

Do you always want to convert "A" to 1, "B" to 2, "C" to 3, ... , "Z" to 26? If so, then the following code will do it:

Code:
lcLetter = "A"   && or any other letter
? ASC(lcLetter) - 64   && will print 1 for A, 2 for B, etc.

I'm not sure if that's what you want, but it's a useful technique to keep in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top