Lingo Dictionary > A-C > charToNum()

 

charToNum()

Syntax

(stringExpression).charToNum
charToNum(stringExpression)

Description

Function; returns the ASCII code that corresponds to the first character of stringExpression.

The charToNum() function is especially useful for testing the ASCII value of characters created by combining keys, such as the Control key and another alphanumeric key.

Director treats uppercase and lowercase letters the same if you compare them using the equal sign (=) operator; for example, the statement put ("M" = "m") returns the result 1 or TRUE.

Avoid problems by using charToNum() to return the ASCII code for a character and then use the ASCII code to refer to the character.

Example

This statement displays the ASCII code for the letter A:

put ("A").charToNum
-- 65

Example

The following comparison determines whether the letter entered is a capital A, and then navigates to either a correct sequence or incorrect sequence in the Score:

on CheckKeyHit theKey
	if (theKey).charToNum = 65 then
		go "Correct Answer"
	else
		go "Wrong Answer"
	end if
end

See also

numToChar()