SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

14.5 LINE INPUT #chnl_num: str_var, str_var...

FORMAT:


        LINE INPUT #chnl_num [, EOF num_var]: str_var, str_var... 

EXAMPLE:

Example 14-14 LINE INPUT#chnl_num statement

  open #1: name 'test_file.txt', access input
  line input #1: line_1$, line_2$ 
  print line_1$, line_2$ 
  close #1 
  end
 
 
This is the first line of text.         This is the second line of text. 

DESCRIPTION:

LINE INPUT #chnl_num reads a line of text from a file. Everything on the line including commas, quotation marks, semicolons, etc., is accepted as part of the input line.

The file must be open and have a channel number associated with it. The simplest version of the LINE INPUT statement is:


        LINE INPUT #chnl_num: str_var 

chnl_num is the channel number associated with the file. The channel number can be any integer expression. str_var is the variable to which data is being assigned. When SheerPower executes the LINE INPUT statement, it reads a line from the file and assigns it to the string variable specified.

LINE INPUT accepts as the input data everything from the beginning of the line up to the first line terminator. The contents of the line---including commas, quotation marks, tabs, leading and trailing spaces, etc.---are assigned to the string variable specified. A string variable must be specified. If a numeric variable is specified, an error will result. If the line being read is empty, SheerPower assigns a null string to the string variable.

14.5.1 EOF Option

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. 

To append data to a file, put the PRINT statement after the LOOP. For example:

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.

14.5.2 Multiple Variables

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.

14.6 ASK #chnl_num:

FORMAT:


        ASK #chnl_num: [NAME str_var][, ZONEWIDTH num_var] [, MARGIN num_var] 
                       [, CURRENT str_var] 

EXAMPLE:

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 

PURPOSE:

ASK #chnl_num is used to find what various characteristics a device is set to.

DESCRIPTION:

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.

14.6.1 ASK Options

An option must be included in the ASK #chnl_num statement. The ask options currently available are described below.

ZONEWIDTH num_var

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 

MARGIN num_var

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 

CURRENT str_var

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 

NAME str_var

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 

14.7 SET #chnl_num: expr

FORMAT:


        SET # chnl_num: [ ZONEWIDTH num_expr ] [, MARGIN int_expr] 
                        [, CURRENT str_expr] 

EXAMPLE:

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 

DESCRIPTION:

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.


Previous Next Contents Index