Previous | Contents | Index |
At an input prompt, there are several commands and keystrokes that the user can enter instead of an answer to the prompt. These are:
Type the word EXIT or press [Ctrl/Z] to exit from a prompt or procedure. If one of these options is entered, Sheerpower sets the internal variable _EXIT to TRUE (1).
If [esc] or the Up-arrow key is entered, the internal variable _BACK will be set to TRUE (1).
Get help for an input item by typing the word HELP or by pressing the [Help] button in the toolbar. If one of these options is input, Sheerpower sets the internal variable _HELP to TRUE (1).
_HELP should be checked before _BACK and/or _EXIT because, in some cases, all three are set on. For example, if "EXIT" is the default and the [Help] key is pressed, both _HELP and _EXIT are set on.
The internal variables _BACK, _EXIT and _HELP can be examined within a program and appropriate action can be taken.
The following keys allow the user to edit input:
Left-arrow | move left |
Right-arrow | move right |
Delete key | delete character(s) to the left of the cursor |
TAB | move to next input field or terminate input |
[CTRL/A] | toggle between insert and overstrike mode |
[CTRL/E] | move to end of line |
[CTRL/H] | move to beginning of line |
[CTRL/J] | delete the word to the left of the cursor. |
[CTRL/U] | delete all the characters on a line. |
[Enter] | terminate the input; [Enter] can be pressed anywhere in the line, not only at the end of the line. |
If the INPUT is to a string variable, the user can enter an unquoted or a quoted string. If the user enters an unquoted string, Sheerpower ignores any leading spaces, trailing spaces, or tabs. An unquoted string cannot contain commas.
If the user enters a quoted string, Sheerpower removes the quotes, and includes any leading or trailing spaces and tabs.
Example 8-6 Inputting Strings |
---|
input 'Enter your name': name1$ input 'Enter your name in quotes': name2$ input 'Enter your name in quotes with spaces': name3$ input 'Enter last name, comma, space, first name in quotes': name4$ print print name1$ print name2$ print name3$ print name4$ end Enter your name? Tony Enter your name in quotes? 'Tony' Enter your name in quotes with spaces? ' Tony ' Enter last name, comma, space, first name in quotes? 'Smith, Tony' Tony Tony Tony Smith, Tony |
8.5.1 Simple Multiple Variables
A single INPUT statement can be used to input several variables. The input items and variables must be separated with commas.
Example 8-7 Inputting Multiple Variables |
---|
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:
Enter 3 names separated by commas? Tom, ? Sue, ? George Tom Sue George |
Whichever method is used, Sheerpower will continue accepting input data until all the variables have values.
It is best to not input directly into a database table(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 into a Table |
---|
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 |
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.
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 |
The PROMPT option displays the specified prompt text without the question mark and space.
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 8-11 PROMPT Option |
---|
input prompt 'Please enter your name: ': name$ print 'Hello '; name$ end Please enter your name: Jackie Hello Jackie |
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.
AT row, col |
row is the row number to print at. col is the column number to print at. row and col can be any integer numeric constants.
Example 8-12 AT row, col 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 |
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.
Previous | Next | Contents | Index |