SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

13.4.2 CONTINUE

FORMAT:


        USE 
          --- 
          ---  CONTINUE 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  CONTINUE 
          --- 
        END HANDLER 

EXAMPLE:

Example 13-7 CONTINUE statement in HANDLER routine

  input 'Enter total sales amount': tsales 
  input 'Enter number of sales': nsales 
  when exception use fix_average 
    average = tsales / nsales 
  end when
  print 'The average is:'; average 
 
  handler fix_average 
    average = 0 
    continue
  end handler
  end
 
        
Enter total sales amount? 18.00 
Enter number of sales? 0 
The average is: 0 

PURPOSE

CONTINUE is used to continue normal program execution at the statement following the one that generated the exception.

DESCRIPTION:

CONTINUE causes SheerPower to exit the exception handler and continue program execution at the first statement following the statement which generated the exception. CONTINUE can only be used in a HANDLER routine.

13.4.3 RESUME

FORMAT:


        USE 
          --- 
          ---  RESUME target 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  RESUME target 
          --- 
        END HANDLER 

EXAMPLE:

Example 13-8 RESUME statement in HANDLER routine

  input 'Enter total sales amount': tsales 
  input 'Enter number of sales': nsales 
  when exception use fix_average 
    average = tsales / nsales 
  end when
  print 'The average is:'; average 
 
  handler fix_average 
    average = 0 
    print 'Invalid numbers.  Try again.' 
    resume 1 
  end handler
  end
 
        
Enter total sales amount? 75.00 
Enter number of sales? 0 
Invalid numbers.  Try again. 
Enter total sales amount? 75.00 
Enter number of sales? 3 
The average is: 25 

PURPOSE:

RESUME is used to resume normal program execution at the routine name or line number that you specify.

DESCRIPTION:

RESUME causes SheerPower to exit the exception handler and resume program execution at the routine name specified.

RESUME can only be used in a handler routine.

13.4.4 EXIT HANDLER

FORMAT:


        USE 
          --- 
          ---  EXIT HANDLER 
          --- 
        END WHEN 
 
           or 
 
        HANDLER handl_name 
          --- 
          ---  EXIT HANDLER 
          --- 
        END HANDLER 

EXAMPLE:

Example 13-9 EXIT HANDLER statement in HANDLER routine

  when exception use mistake 
    input 'Enter your age': age 
  end when
  print 'You are'; age; 'years old' 
 
  handler mistake 
    print 'Oops...' 
    delay 2 
    exit handler
  end handler
  end
 
        
Enter your age? 3x 
Oops... 
Non-numeric input when number expected at 10.1 
Enter your age? 35 
You are 35 years old 

PURPOSE:

EXIT HANDLER is used to exit a handler routine and pass the exception up to the next level of exception handling.

DESCRIPTION:

EXIT HANDLER exits the current HANDLER routine. If the current handler is nested within another handler, SheerPower jumps to the outside handler and executes the code for that handler. If there is no other exception handler, control returns to the SheerPower system. SheerPower prints the exception message and takes whatever action it normally would.

EXIT HANDLER can only be used within an exception handler.


Chapter 14
File Handling

Files are places where information is stored. Files can be accessed from within SheerPower programs, but files exist outside of the program. Therefore, when a program ends, the file and the information in it still exists. The next time the program is run, the file can be accessed and old information removed from it, and new information stored in it.

Files are stored on devices: disks, tapes, etc. They are stored under file specifications, which include a device name.

The following pages describe the SheerPower statements used to manipulate files.

Note

See Section 6.7, File and Structure Access Functions for more on working with files in SheerPower. For example Section 6.7.5, FINDFILE$(str_expr [, int_expr]) to process a series of files, or batch files.

14.1 OPEN #chnl_num: NAME ...

FORMAT:


        OPEN #chnl_num: NAME 'file_spec' 
               [, ACCESS INPUT| OUTPUT | OUTIN ] [, UNFORMATTED] 
               [, UNIQUE] [, OPTIMIZE OFF] 

EXAMPLE:

Example 14-1 OPEN#chnl_num statement - opening files

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

PURPOSE:

OPEN opens a file so it can be read and written to. OPEN can also create a file.

DESCRIPTION:

OPEN either opens an existing file or creates a new one. #chnl_num is the channel number associated with the file. chnl_num can be any integer number in the range of 1 to 95. (0 is the channel number associated with the terminal. Channel number 0 cannot be opened or closed.) The channel number is used to refer to the file. The channel number must be unique. If a channel number is already associated with an open file, an exception is generated.

file_spec gives the file specification of the file being opened. The file specification can be any string expression.

14.1.1 OPEN FILE num_var: NAME ...

FORMAT:


        OPEN FILE num_var: NAME 'file_spec' 
               [, ACCESS INPUT| OUTPUT | OUTIN ] [, UNFORMATTED] 
               [, UNIQUE] [, OPTIMIZE OFF] [, LOCKED] 

EXAMPLE:

Example 14-2 OPEN FILE statement - opening files

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

PURPOSE:

The OPEN FILE statement is used to open existing files or create new files. You can also access webpage data using the html:// file open option, or send emails with the mailto:// file open option. See Chapter 19, Writing Network Applications and Accessing Devices for complete details.

DESCRIPTION:

OPEN either opens an existing file or creates a new one. The OPEN FILE syntax looks up a free channel, stores the channel into varname, and then opens the file.

file_spec gives the file specification of the file being opened. The file specification can be any string expression.

14.1.2 Logicals

In SheerPower, the @ sign is a LOGICAL that is translated from being just an "@" to the full PATH of the folder that the current application is being run from. For example:


  open #1: name '@filename', access outin 

sheerpower: is also a logical. If the file to be opened is inside the SheerPower folder, it can be opened as:


  open #1: name 'sheerpower:filename', access outin 

You can also open a file using the full path of where the file is located. For example:


  open #1: name 'c:\foldername\filename', access outin 

In SheerPower you can make your own logicals. See Section 11.14.6, SET SYSTEM, LOGICAL: VALUE.

14.1.3 OPEN Options

The OPEN statement has several options. Multiple options are separated with commas.

14.1.3.1 ACCESS Option

The ACCESS option specifies one of three input/output options. These options tell SheerPower whether you want to input (read) data, output (store) data or input and output data.


Previous Next Contents Index