Read, Read -45, Purpose – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 235: Syntax, Example

Advertising
background image

Publication 1746-RM001A-US-P

Input Functions 13-45

READ

Purpose

Use the READ statement to retrieve the expressions that are specified in the DATA
statement and assign the value of the expression to the variable in the READ
statement. The READ statement is always followed by one or more variables. If
more than one variable follows a READ statement, they are separated by a comma.

Syntax

READ

Example

>1

REM EXAMPLE PROGRAM

>10 FOR I = 1 TO 3

>20 READ A,C

>30 PRINT A,C

>40 NEXT I

>50 RESTORE

>60 READ A,C

>70 PRINT A,C

>80 DATA 10,20,10/2,20/2,SIN(PI),COS(PI)

READY

>RUN

10

20

5

10

0 -1

10

20

READY

>

Every time a READ statement is encountered the next consecutive expression in
the DATA statement is evaluated and assigned to the variable in the READ
statement. You can place DATA statements anywhere within a program. They are
not executed and do not cause an error. DATA statements are considered chained
together and appear as one large DATA statement. If at anytime all the data is read
and another READ statement is executed, the program terminates and the message

ERROR: NO DATA - IN LINE XX

prints to the console device.

Advertising