Reading and Writing

From Shopbot Wiki

(Difference between revisions)
(New page: == 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 th...)
Current revision (21:47, 18 January 2008) (edit) (undo)
m
 
Line 13: Line 13:
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:
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 #1''
+
:''OPEN coordlist.txt FOR OUTPUT as #2''
-
:''WRITE #1, %(1)''
+
:''WRITE #2, %(1)''
-
:''WRITE #1, %(2)''
+
:''WRITE #2, %(2)''
-
:''WRITE #1, %(3)''
+
:''WRITE #2, %(3)''
-
:''CLOSE #1''
+
:''CLOSE #2''

Current revision

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