Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual
Page 35

Publication 1746-RM001A-US-P
Expressions and Operators 3-13
When you use the ASC operator as shown above, the $([expr]) denotes what string
is accessed. The expression after the comma selects an individual character in the
string. In the above example, the first character in the string is selected. The
decimal representation for the ASCII character T is 84. String character position 0
is invalid.
>NEW
>1
REM EXAMPLE PROGRAM
>5
STRING 1000,40
>10 $(1)=“ABCDEFGHIKJL”
>20 FOR X = 1 TO 12
>30 PRINT ASC($(1),X),
>40 NEXT X
>50 END
READY
>RUN
65
66
67
68
69
70
71
72
73
75
74
76
READY
>
The numbers printed in the previous example represent the ASCII characters A
through L.
You can also use the ASC operator to change individual characters in a defined
string.
In general, the ASC operator lets you manipulate individual characters in a string.
A simple program can determine if two strings are identical.
>NEW
>1
REM EXAMPLE PROGRAM
>5
STRING 1000,40
>10 $(1) = “ABCDEFGHIJKL”
>20 PRINT $(1)
>30 ASC($(1),1) = 75 : REM DECIMAL EQUIVALENT OF K
>40 PRINT $(1)
>50 ASC($(1),2) = ASC($(1),3)
>60 PRINT $(1)
READY
>RUN
ABCDEFGHIJKL
KBCDEFGHIJKL
KCCDEFGHIJKL
READY
>