11.04.2013 Views

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Parameter Description<br />

Examples<br />

In the following example, the program segment reads CLIENT.NAME from the<br />

CLIENTS file, record ID 10034, attribute 2. If the record exists, UniData appends the<br />

attribute to string NAME.ARRAY1 using the short form of the replace command.<br />

Otherwise, UniData executes the ELSE clause.<br />

1-648 <strong>UniBasic</strong> <strong>Commands</strong> <strong>Reference</strong><br />

ON ERROR statements Specifies statements to execute if the READV statement fails<br />

with a fatal error because the file is not open, an I/O error occurs,<br />

or UniData cannot find the file.<br />

If you do not specify the ON ERROR clause and a fatal error<br />

occurs, the program terminates.<br />

THEN statements END THEN executes if the read is successful. END is required to<br />

terminate multiline THEN statements.<br />

ELSE statements END ELSE executes if the read is not successful or the record does not<br />

exist. END is required to terminate multiline ELSE statements.<br />

READV Parameters (continued)<br />

NAME.ARRAY1 = "Smith Jones Brown"<br />

OPEN "CLIENTS" TO CLIENT.FILE ELSE STOP<br />

READV CLIENT.NAME FROM CLIENT.FILE,"10034",2 THEN<br />

NAME.ARRAY1 = CLIENT.NAME<br />

PRINT NAME.ARRAY1<br />

END ELSE<br />

PRINT 'NO FILE FOR CLIENT ':CLIENT.ID<br />

END<br />

In the next example, you can use the READV command with an attribute.expr of 0<br />

to verify that a record exists (for example, if you are assigning IDs sequentially in the<br />

CLIENTS file). Each time you need to create a new ID, you need to verify that the<br />

ID you selected is not in use. The following code accomplishes this task, incrementing<br />

the ID until an ID is available.<br />

LOOP<br />

READV CHECK FROM CLIENT,NEXT.ID,0 ELSE CHECK = 0<br />

UNTIL CHECK NE 0 DO<br />

NEXT.ID += 1<br />

REPEAT CLIENT.ID = NEXT.ID

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!