11 - 4 11 - 4
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
ASC
Function
ASCii
• Returns the character code corresponding to the starting character of the character string
expression.
ASC ( <character string expression> )
Syntax
character string expression
• • • •
Specify the character string to return a character
code.
A=ASC(“BASIC”)
• • • •
Stores the character code (42
H
) of the starting
character B of the character string to A.
Examples
C=ASC(“D”)
• • • •
Stores the character code (44
H
) of character “D” to
C.
Description
• The ASC function returns the character code that corresponds to the starting character of
<character string expression>.
• If an empty character string is specified in < character string expression>, an “Illegal
function call” error occurs.
Program Example
10 ' Displays the character code of the starting character of a character string
20 A$="AD51H-BASIC"
:
' Defines the character string
30 CODE=ASC(A$)
:
' Returns the character code
40 PRINT "Character =";CHR$(CODE)
:
' Displays the character
50 PRINT "Decimal =";CODE
:
' Character code (decimal)
60 PRINT "Hexadecimal =";HEX$(CODE)
: '
(hexadecimal)
70 END
RUN
Character =A
Decimal= 65
Hexadecimal=41
OK
REMARK
• See the CHR$ and HEX$ functions.
• For converting from a character code numeric value to a character string, see the
CHR$ function.