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!

How to convert characters into numbers?

Status
Not open for further replies.

venado

Programmer
Nov 28, 2000
35
CA
I need to convert characters to numbers. i.e. ASC('A') = 65.
That's fine. How about "AB" or "AC", and so on ...

Does anyone knows about of any vfp capability to do that.

Any help is appreciated.

Thanks,
venado
 
Venado,
Do you want the numbers in a comma delimited string? In an array? In an integer? (The last would only work for up to 4 characters.)

You'll have to give a bit more information on what you are trying to do before a recommendation can be made.

Rick
 
More info.....

I want the numbers in an integer for further manipulation. The 4 digits will be fine for the purpose of this exercise.

Thanks
 
If you meant '4 bytes', not 'digits', and you need this to convert binary representation of the number in the string to the numeric variable in VFP (it is used very often when working with API functions), use following:

asc(left(MyString,1)) + asc(substr(MyString,2,1)) * 256 +
asc(substr(MyString,3,1)) * 256*256 + ;
asc(substr(MyString,4,1)) * 256*256*256

Hope this helps.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
If you want to play with the numbers after segmenting them out use an array

lcString = "ADFK" or whatever
lnLen = len(lcString)
dimension laArray(lnLen)
for lnX = 1 to lnLen
laArray = asc(substr(lcString , lnX , 1)
endfor
..
code to play with the array
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
lcString = "ADFK" or whatever
lnLen = len(lcString)
dimension laArray(lnLen)
for lnX = 1 to lnLen
laArray[lnX] = asc(substr(lcString , lnX , 1)
endfor
..
code to play with the array


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
lol, Thanks Vald for correcting my code

David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Thank you all for yours tips. It was very helpful.
venado
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top