Reading and Writing

From Shopbot Wiki

Reading and Writing Text Files

The ShopBot software can both read values in from a text file, and write to a text file. To read from a file, you start with the OPEN command using the FOR INPUT option and with a unique file indentifier #. You would then read data from the file using the INPUT #? command, and close it with the CLOSE #? command. If our example file file had three values in it, we could use this method to read those values and move to that coordinate:

OPEN coordlist.txt FOR INPUT as #1
INPUT #1, &newx
INPUT #1, &newy
INPUT #1, &newz
M3, &newx, &newy. &newz
CLOSE #1


The syntax for Writing to a file is very similar. Instead of opening the file FOR INPUT, you open it FOR OUTPUT, and instead of using the INPUT #? statement to read, you use the WRITE #? to write to it. A similar example to the one above might write the current location to a text file like this, using the system variables for the X, Y, and Z coordinates:

OPEN coordlist.txt FOR OUTPUT as #2
WRITE #2, %(1)
WRITE #2, %(2)
WRITE #2, %(3)
CLOSE #2

Contributors
BillYoung
Personal tools