SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

8.5 Inputting Multiple Variables

8.5.1 Simple Input Statement

A single INPUT statement can be used to input several variables. The input items and variables must be separated with commas.

Example 8-7 Simple input statement

  input 'Enter 3 names separated by commas': name1$, name2$, name3$ 
  print name1$, name2$, name3$ 
  end
 
        
Enter 3 names separated by commas? Tom, Sue, George 
 
Tom                 Sue                 George 

If an INPUT statement contains a list of variables, SheerPower asks for input until all of the variables have a value. If the user enters less data or more data than there are variables, SheerPower generates an exception. If an exception occurs, SheerPower restarts from the beginning.

Users can enter the data for a variable list in one of the following two ways:

  1. The user can enter each piece of data on a separate line by typing a comma as the last character on each continuing line. The comma tells SheerPower that there is more data to come.


            
            Enter 3 names separated by commas? Tom, 
            ? Sue, 
            ? George 
     
            Tom                 Sue                 George 
    

  2. Users can enter the data on one line by separating the data with commas as shown in the first example above.

Whichever method is used, SheerPower will continue accepting input data until all the variables have values.

Validating Data

It is best to not input directly into a structure(field)---but to instead always go through an intermediate variable that is a numeric or string variable:

Instead of:


  line input 'Last name': client(last_name) 

Use:


  line input 'Last name': last_name$ 
  client(last_name) = last_name$ 

This validates the data prior to storing it into the structure. For example:

Example 8-8 Validating data prior to storing it into a structure

  do
    input 'Last name': last_name$ 
    if _exit then exit do
    if len(last_name$) < 2 then
      message error: 'Too short of a name' 
      repeat do
    end if
    client(last_name) = last_name$ 
  end do

8.5.2 LINE INPUT Statement

A number of variables can be input with one LINE INPUT statement. Simply list the variables separated by line terminators.

Example 8-9 LINE INPUT statement

  line input 'Enter a comment, press Enter, enter a comment': &
       comment_1$, comment_2$ 
  print
  print comment_1$ 
  print comment_2$ 
  end
 
        
Enter a comment, press Enter, enter a comment? This is the first comment 
? This is the second comment 
 
This is the first comment 
This is the second comment 

SheerPower asks for input until all of the variables listed have received a value.

Unlike the INPUT statement, commas cannot be used to separate answers. Each variable is prompted for separately. If a comma is in a user's response, the comma is just taken as part of the text.

8.6 INPUT Default Prompt and Text

By default, SheerPower prints a question mark and a space and then waits for the user's response. To display prompt text before the question mark, enclose the prompt text in quotes and follow it with a colon. The colon separates the prompt text from the variable(s). The prompt text must follow the keyword INPUT and must be separated from the variable list by a colon.

When SheerPower executes the INPUT statement, it prints the prompt text ("Your name" in the example below) followed by a question mark and a space.

Example 8-10 Input default prompt and text

  input 'Your name': name$ 
  print name$ 
  end
 
        
Your name? Fred 
Fred 

8.7 PROMPT Option

The PROMPT option displays the specified prompt text without the question mark and space.

FORMAT:


        PROMPT str_expr 

str_expr is a string expression which contains the prompt text. str_expr can be any string expression. The prompt text is separated from the variable list with a colon (:).

EXAMPLE:

Example 8-11 PROMPT option

  input prompt 'Please enter your name: ': name$ 
  print 'Hello '; name$ 
  end
 
        
Please enter your name: Jackie 
Hello Jackie 

8.8 AT Option

The AT option positions the cursor on the specified row and column. This is the position where the INPUT statement starts the prompt, not where the user enters data.

FORMAT:


        AT row, col 

row is the row to print at. col is the column to print at. row and col can be any integer numeric constants.

EXAMPLE:

Example 8-12 AT option

  print at 1, 1: 
  input at 3, 10, prompt 'Please enter your name: ': name$ 
  print 'Hello '; name$ 
  end
 
        
 
      Please enter your name: Jack    <-----this line gets printed at row 3, column 10 
Hello Jack 

8.9 ATTRIBUTES option

The ATTRIBUTES option allows input with attributes. The available attributes are:

BOLD
BLINK
REVERSE

Multiple attributes used in one INPUT statement are separated by commas.

FORMAT:


        ATTRIBUTES attr_list 

attr_list contains a list of input attributes.

EXAMPLE:

Example 8-13 ATTRIBUTES Option

  name_attr$ = 'bold, blink' 
  line input 'Enter your name', attributes name_attr$: name$ 
  print 'Hello '; name$ 
  end
 
        
Enter your name? Susan
Hello Susan 

8.10 LENGTH Option

The LENGTH option limits the number of characters that a user can enter. It causes SheerPower to display underscore characters following the prompt. The number of underscore characters is the length.

FORMAT:


        LENGTH num_expr 

num_expr is the number of characters the user can enter.

EXAMPLE:

Example 8-14 LENGTH option

  input 'Enter your name', length 15: name$ 
  input 'Enter a city', length 20: city$ 
  print name$, city$ 
  end
 
        
Enter your name? Betty__________ 
Enter a city? 'San Diego'_________ 
Betty               San Diego 

8.11 DEFAULT Option

DEFAULT lets you provide defaults for INPUT statements. SheerPower automatically formats the default appropriately. The user can press [Enter] to accept the default you provide.

FORMAT:


        DEFAULT str_expr 

str_expr is a string expression that will be used as the default. When SheerPower executes an INPUT statement with a default, it prints the default after the prompt.

EXAMPLE:

Example 8-15 DEFAULT option

  input 'Enter the state code', default 'CA': state$ 
  print 'The state was: '; state$ 
  end
 
                            
Enter the state code? CA 
The state was: CA 

If the user does not want the default, they can simply type over the default text.

8.11.1 Pre-positioning to a DEFAULT Menu Item

When performing an INPUT MENU, the DEFAULT option can be used to specify a default menu path. The default takes the format of:


        #item1;#item2;... 

#item1 is the number of the item on the first menu, #item2 is the number of the item on the second menu, and so on.

Upon the completion of a INPUT MENU statement, the concept _STRING contains the menu path taken by the user when selecting the menu item; i.e., #2;#3 means the 3rd item of the 2nd submenu. (For information on menus, see Section 8.18, MENU Option.)

EXAMPLE:

Example 8-16 _STRING system function

  line1$ = '%width 12, %menubar,' 
  line2$ = 'file = {new, get_file, save, save_as},' 
  line3$ = 'edit = {cut, copy, paste},' 
  line4$ = 'paragraph = {font, alignment, spacing, tabs, headers, footers},' 
  line5$ = 'options = {ruler = {on, off}, side_bar = {on, off},' 
  line6$ = 'view = {enlarged, normal, small}},exit' 
  test_menu$ = line1$ + line2$ + line3$ + line4$ + line5$ + line6$ 
  the_default$ = '' 
  do 
    input menu test_menu$, default the_default$: ans$ 
    if  _exit  then  exit do
    message 'Menu path was', _string
    the_default$ = _string
  loop
  end
 
 
+------------------------------------------------------------------------------+ 
|  FILE      |   EDIT      |   PARAGRAPH   |   OPTIONS   |   EXIT              | 
+--------------------------------------------+---OPTIONS---+-------------------+ 
                                             |  RULER    [>| 
                                             |  SIDE_BAR +----VIEW-----+ 
                                             |  VIEW     |  ENLARGED   | 
                                             +-----------|  NORMAL     | 
                                                         |  SMALL      | 
                                                         +-------------+ 
                                                         

The menu path was: #4;#3;#2


Previous Next Contents Index