UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

Examples The following program segment places in select list 1 all record IDs in the CLIENTS file, and then prints the ID of the first record: 1-704 UniBasic Commands Reference OPEN 'CLIENTS' TO CLIENT ON ERROR PRINT "File open error." THEN PRINT "OPEN" SELECT CLIENT TO 1 READNEXT var FROM 1 ON ERROR PRINT "Error in READNEXT." THEN PRINT var END ELSE PRINT "Record not found." END The following sample program creates a select list that is named rather than numbered. This program is compiled in BASICTYPE P, but compiles and runs in all BASICTYPEs. $BASICTYPE "P" list = '' OPEN 'INVENTORY' TO INV_FILE ELSE PRINT "OPEN error" SELECT INV_FILE TO list FOR X = 1 TO 10 READNEXT ID FROM list ELSE PRINT "No more IDs in list" END READU REC FROM INV_FILE,ID THEN PRINT "Record ":X:" is ":REC:" ":REC END ELSE PRINT "Record not found." END NEXT X END Here is the output for this program: Record 1 is 10105 Memory Record 2 is 10076 Telephone Record 3 is 10020 Adapter Record 4 is 10086 Modem Record 5 is 10092 Adapter Record 6 is 10073 Monitor Record 7 is 10041 Computer Record 8 is 10071 Computer Record 9 is 10103 Telephone Record 10 is 10101 Computer In the following example, the program statement creates a list of all record IDs in the INVENTORY file in active select list 0: SELECT INVENTORY

In the next example, the program segment first creates a list of all IDs in the ORDERS file and assigns the ID list to list 1. It then uses the READNEXT command to read the IDs from the list sequentially, executing a subroutine, PROCESS.ORDERS, each time. SELECT ORDERS TO 1 LOOP READNEXT ORDER.ID FROM 1 ELSE TAPE.ID = " " WHILE ORDER.ID GOSUB PROCESS.ORDERS REPEAT Related Commands UniBasic DELETELIST, FORMLIST, READLIST, SELECTINDEX, SELECTINFO, WRITELIST UniQuery DELETE.LIST, GET.LIST, SAVE.LIST, SELECT, SSELECT – For information, see the UniQuery Commands Reference. UniData SQL SELECT – For information, see the UniData SQL Commands Reference. SELECT 1-705

Examples<br />

The following program segment places in select list 1 all record IDs in the CLIENTS<br />

file, and then prints the ID of the first record:<br />

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

OPEN 'CLIENTS' TO CLIENT ON ERROR PRINT "File open error." THEN<br />

PRINT "OPEN"<br />

SELECT CLIENT TO 1<br />

READNEXT var FROM 1 ON ERROR PRINT "Error in READNEXT." THEN<br />

PRINT var<br />

END ELSE<br />

PRINT "Record not found."<br />

END<br />

The following sample program creates a select list that is named rather than<br />

numbered. This program is compiled in BASICTYPE P, but compiles and runs in all<br />

BASICTYPEs.<br />

$BASICTYPE "P"<br />

list = ''<br />

OPEN 'INVENTORY' TO INV_FILE ELSE PRINT "OPEN error"<br />

SELECT INV_FILE TO list<br />

FOR X = 1 TO 10<br />

READNEXT ID FROM list ELSE<br />

PRINT "No more IDs in list"<br />

END<br />

READU REC FROM INV_FILE,ID THEN<br />

PRINT "Record ":X:" is ":REC:" ":REC<br />

END ELSE<br />

PRINT "Record not found."<br />

END<br />

NEXT X<br />

END<br />

Here is the output for this program:<br />

Record 1 is 10105 Memory<br />

Record 2 is 10076 Telephone<br />

Record 3 is 10020 Adapter<br />

Record 4 is 10086 Modem<br />

Record 5 is 10092 Adapter<br />

Record 6 is 10073 Monitor<br />

Record 7 is 10041 Computer<br />

Record 8 is 10071 Computer<br />

Record 9 is 10103 Telephone<br />

Record 10 is 10101 Computer<br />

In the following example, the program statement creates a list of all record IDs in the<br />

INVENTORY file in active select list 0:<br />

SELECT INVENTORY

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

Saved successfully!

Ooh no, something went wrong!