The asc operator – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 109

Advertising
background image

Operating Functions

Chapter 5

5–72

Two operators in the BASIC Module can manipulate STRINGS. These
operators are ASC() and CHR(). The ASC() operator returns the integer
value of the ASCII character placed in the parentheses.

Example:

uPRINT ASC(A)

65

The decimal representation for the ASCII character “A” is 65. In addition,
you can evaluate individual characters in a pre-defined ASCII string with
the ASC() operator.

Example:

u5 STRING 1000,40

u10 $(1)=“THIS IS A STRING”

u20 PRINT $(1)

u30 PRINT ASC($(1),1)

u40 END

uRUN

THIS IS A STRING
84

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.

Example:

u5 STRING 1000,40

u10 $(1)=“ABCDEFGHIJKL”

u20 FOR X=1 TO 12

u30 PRINT ASC($(1),X),

u40 NEXT X

u50 END

uRUN

65 66 67 68 69 70 71 72 73 74 75 76

The numbers printed in the previous example represent the ASCII
characters A through L.

5.10.1
The ASC Operator

Advertising