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

Converting Character to Interger

Status
Not open for further replies.

kedrew

Programmer
Jun 22, 2001
29
US
I'm trying obtain the decimal value of a character.

The function is to receive a single character, convert it to an interger and then do the remainder of it's processing.
However, no matter what I've tried, I always get an error message.

Error messages include:
Code:
   Type mismatch: 'CInt'             [n = CInt(a)]
   Type mismatch: '[string: "a"]'    [n = Int("a")]

The beginning of the function is as follows:
Code:
Sub Break (a, b, c)

	Dim t,x
	x = CInt(a)
	
	If (x >= 128) Then
		t = t +   8
		x = x - 128
	End If

I can successfully convert from an interger to a character, I just cannot go the other way. I'm originally from a C++ background, so I feel this should be an easy item.

I have tried also tried CByte and CLng and I get the same error messages.
 
Try something from the Asc family. I can't remember the differances now, but Asc functions will allow you to convert a character to it's ASCII representation.
num = Asc(char) to reverse: char = chr(num)
num = AscB(char) to reverse: char = chrB(num)
num = AscW(char) to reverse: char = chrW(num)

If you wanted the order from the alphabet (a=1, b=2, etc) than before you feed your character to the Asc function ucase it, convert it with Asc, subtract 64
for example:
Code:
A => Asc('A') = 65
  => 65 - 64 = 1

or:
a => ucase('a') = 'A'
  => Asc('A') = 65
  => 65 - 64 = 1
-Tarwn

----------------------
| if(u=getc(this)) |
| putc('\a'); |
----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top