Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 110

Advertising
background image

Operating Functions

Chapter 5

5–73

You can also use the ASC() operator to change individual characters in a
defined string.

Example:

u5 STRING 1000,40

u10 $(1)=“ABCDEFGHIJKL”

u20 PRINT $(1)

u30 ASC($(1),1)=75 REM: DECIMAL EQUIVALENT OF K

u40 PRINT $(1)

u50 ASC($(1),2)=ASC($(1),3)

u60 PRINT $(1)

uRUN

ABCDEFGHIJKL
KBCDEFGHIJKL
KCCDEFGHIJKL

In general, the ASC() operator lets you manipulate individual characters in
a string. A simple program can determine if two strings are identical.

Example:

u5 STRING 1000,40

u10 $(1)=“SECRET” : REM SECRET IS THE PASSWORD

u20 INPUT “WHAT’S THE PASSWORD – ”,$(2)

u30 FOR I=1 TO 6

u40 IF ASC($(1),I)=ASC($(2),I) THEN NEXT I ELSE 70

u50 PRINT “YOU GUESSED IT!”

u60 END

u70 PRINT “WRONG, TRY AGAIN” : GOTO 20

uRUN

WHAT’S THE PASSWORD – SECURE
WRONG, TRY AGAIN WHAT’S THE
PASSWORD – SECRET
YOU GUESSED IT

5.10.1
The ASC Operator
(continued)

Advertising