Previous | Contents | Index |
The EOF option of LINE INPUT causes Sheerpower to return a TRUE/FALSE value indicating when the end-of-file has been reached. This eliminates the need for an error handler when reading files. The format is:
LINE INPUT #chnl_num, EOF num_var: str_var |
Example 14-15 EOF option with LINE INPUT |
---|
ven_ch = _channel open #ven_ch: name 'test_file.txt' do line input #ven_ch, eof endfile?: datafile$ if endfile? then exit do print 'line was: '; datafile$ loop close #1 end line was: This is the first line of text. line was: This is the second line of text. |
Example 14-16 Appending data to a file |
---|
open file myfile_ch: name 'myfile.txt', access outin do line input #myfile_ch, eof eof?: z0$ if eof? then exit do loop print #myfile_ch: 'This is a new line added to the file' close #myfile_ch |
_CHANNEL is the next available channel number.
LINE INPUT can be used to read several lines of data from a file. To read more than one item, separate the string variables with commas. Lines are read sequentially, starting from the beginning of the file, and assigned to the variables listed.
Example 14-17 Multiple variables in LINE INPUT#chnl_num |
---|
open #1: name 'test_file.txt', access input line input #1: line_1$, line_2$ print '1 '; line_1$ print '2 '; line_2$ close #1 end 1 This is the first line of text. 2 This is the second line of text. |
If an attempt is made to input more data than the file contains, Sheerpower generates an exception.
ASK #chnl_num: [NAME str_var][, ZONEWIDTH num_var] [, MARGIN num_var] [, CURRENT str_var] |
Example 14-18 ASK#chnl_num statement |
---|
open #3: name 'storage.ars', access output ask #3: zonewidth x print 'The current print zone width is'; x close #3 end The current print zone width is 20 |
ASK #chnl_num is used to find what various characteristics a device is set to.
ASK returns the characteristic of the device specified and stores the value in a num_var or str_var. chnl_num is an optional channel number. If no channel number is specified, Sheerpower checks the default device. If a channel number is specified, Sheerpower checks the device associated with that channel number.
An option must be included in the ASK #chnl_num statement. The ask options currently available are described below.
ASK #chnl_num: ZONEWIDTH finds the print zone width of the device specified and assigns the value to the numeric variable num_var.
Example 14-19 ASK#chnl_num: ZONEWIDTH |
---|
open #3: name 'storage.ars', access output ask #3: zonewidth x print 'The current print zone width is'; x close #3 end The current print zone width is 20 |
ASK MARGIN finds the right margin of the device specified and assigns its value to the numeric variable num_var.
Example 14-20 ASK#chnl_num: MARGIN |
---|
open #3: name 'test_file.txt', access output ask #3: margin marg print 'The current margin is'; marg close #3 end The current margin is 132 |
ASK #chnl_num: CURRENT is used to store a current record value into the str_var.
Example 14-21 ASK#chnl_num: CURRENT |
---|
open #1: name 'temp.txt', access output for z = 1 to 20 print #1: 'This is line number '; z next z close #1 open #1: name 'temp.txt' for i = 1 to 5 line input #1: a$ next i ask #1: current c$ print '5th item was: '; a$ for i = 1 to 5 line input #1: a$ next i print '10th item was: '; a$ set #1: current c$ line input #1: a$ print 'Back to 5th item again: '; a$ close #1 end 5th item was: This is line number 5 10th item was: This is line number 10 Back to 5th item again: This is line number 5 |
ASK #chnl_num: NAME asks the Sheerpower operating system for the file specification of the file open on channel #chnl_num and stores the value into str_var.
Example 14-22 ASK#chnl_num: NAME |
---|
out_ch = 12 open #out_ch: name 'sheerpower:minutes.txt', & access output ask #out_ch: name x$ print x$ close #out_ch end c:SHEERPOWER\minutes.txt |
SET # chnl_num: [ ZONEWIDTH num_expr ] [, MARGIN int_expr] [, CURRENT str_expr] |
Example 14-23 SET#chnl_num statement |
---|
open #3: name 'storage.ars', access output ask #3: zonewidth x print 'The current print zone width is'; x set #3: zonewidth 35 ask #3: zonewidth x print 'The new print zone width is'; x close #3 end The current print zone width is 20 The new print zone width is 35 |
SET #chnl_num sets various device characteristics. chnl_number is a channel number. If no channel number is specified, Sheerpower sets the default device (the terminal). If a channel number is specified, Sheerpower sets the device associated with that channel number.
When a device characteristic is SET, it remains set until the device is closed. Therefore, if the terminal is SET, it will remain SET until you exit from the Sheerpower environment or the SET statement is used again.
An option must be included with the SET #chnl_num statement. The set options currently available are described below:
SET #chnl_num: ZONEWIDTH sets the print zone width of the device specified to the number designated. num_expr indicates the width to set the device's print zones. See above example.
SET #chnl_num: MARGIN sets the right margin on the device specified to the number indicated. int_expr specifies the column to set the margin to. The margin must be greater than the zone width.
Example 14-24 SET#chnl_num: MARGIN |
---|
open #3: name 'storage.ars', access output set #3: margin 45 print #3: repeat$('1234567',10) close #3 open #3: name 'storage.ars', access input do line input #3, eof endfile?: item$ if endfile? then exit do print item$ loop close #3 end 123456712345671234567123456712345671234567123 4567123456712345671234567 |
SET #chnl_num: CURRENT sets the current record to that specified by str_expr. The str_expr contains the information for the record you want to make current.
Example 14-25 SET#chnl_num: CURRENT |
---|
open #1: name 'temp.txt', access output for z = 1 to 20 print #1: 'This is line number '; z next z close #1 open #1: name 'temp.txt' for i = 1 to 5 line input #1: a$ next i ask #1: current c$ print '5th item was: '; a$ for i = 1 to 5 line input #1: a$ next i print '10th item was: '; a$ set #1: current c$ line input #1: a$ print 'Back to 5th item again: '; a$ close #1 end 5th item was: This is line number 5 10th item was: This is line number 10 Back to 5th item again: This is line number 5 |
Previous | Next | Contents | Index |