Cogs and Levers A blog full of technical stuff

UniVerse BASIC cheatsheet

A cheatsheet for writing UniVerse BASIC programs

Program Management

Creating a directory for programs

> CREATE.FILE BP 19

Creating a file to store a program

> ED BP PROGRAM.NAME

Compiling a program

> BASIC BP PROGRAM.NAME

Running a program

> RUN BP PROGRAM.NAME 

Sourcecode Editing

Formatting sourcecode

----: FORMAT 

File IO

Opening a file

0001= OPEN 'filename' TO FILE.VAR ELSE STOP "Couldn't open filename" 

Reading a record from a file

0001= READ RECORD.VAR FROM FILE.VAR, 'RELLEVEL' ELSE RECORD.VALUE = '' 

Writing a record to a file

0001= WRITE RECORD.VAR TO FILE.VAR, 'TEST.WRITE' 

Reading a record from a file into an array

0001= MATREAD RECORD.VAR FROM FILE.VAR, 'RELLEVEL' ELSE MAT RECORD.VAR = '' 

Writing a record from an array into a file

0001= MATWRITE RECORD.VAR TO FILE.VAR, 'TEST.WRITE' 

Reading a single field from a file

0001= READV TYPE.DESC FROM FILE.VAR, 'RELLEVEL', 1 ELSE TYPE.DESC = '' 

Writing a single field to a file

0001= WRITEV TYPE.DESC TO FILE.VAR, 'TEST.WRITE', 1 

Deleting a record from a file

0001= DELETE FILE.VAR, 'RELLEVEL' 

Locking records for update

0000= READU RECORD.VAR FROM FILE.VAR, 'RELLEVEL' LOCKED 
0000= MATREADU RECORD.VAR FROM FILE.VAR, 'RELLEVEL' LOCKED 
0000= READVU TYPE.DESC FROM FILE.VAR, 'RELLEVEL' LOCKED 

Locking records from read

0000= READL RECORD.VAR FROM FILE.VAR, 'RELLEVEL' 
0000= MATREADL RECORD.VAR FROM FILE.VAR, 'RELLEVEL' 
0000= READVL TYPE.DESC FROM FILE.VAR, 'RELLEVEL' 

An example record read

0001= OPEN 'VOC' TO VOC.FILE ELSE STOP "Can't open VOC" 
0002= READ VOC.RECORD FROM VOC.FILE, 'RELLEVEL' ELSE VOC.RECORD = '' 
0003= PRINT VOC.RECORD 

An example record read to an array

0001= DIM VOC.RECORD(10) 
0002= OPEN 'VOC' TO VOC.FILE ELSE STOP "Can't open VOC" 
0003= MATREAD VOC.RECORD FROM VOC.FILE, 'RELLEVEL' ELSE MAT VOC.RECORD = '' 
0004= FOR FIELD.NUMBER = 1 TO 10 
0005= PRINT VOC.RECORD(FIELD.NUMBER) 
0006= NEXT FIELD.NUMBER 

An example record read from a select list

0001= OPEN 'VOC' TO VOC.FILE ELSE STOP "Can't open VOC" 
0002= EOF = 0 
0003= EXECUTE 'SELECT VOC WITH TYPE = "M"' 
0004= LOOP 
0005= READNEXT VOC.KEY ELSE EOF = 1 
0006= UNTIL EOF 
0007= PRINT VOC.KEY 
0008= REPEAT 

References

life, the universe, and everything