Previous | Contents | Index |
num_var++ |
It is commonplace to increment a numeric variable:
total = total + 1 lines = lines + 1 |
Sheerpower provides a shorthand syntax for incrementing numeric variables:
total++ lines++ |
LSET, RSET and CSET assign string values to variables. LSET left-justifies, RSET right-justifies, and CSET center-justifies the new value. These statements can be used to assign only string values.
LSET, RSET and CSET justify the new value within the length of the previous value. For example, in the following program, HEADING$ has a length of twenty characters and consists of twenty dots:
Example 5-7 LSET, RSET and CSET |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$; ')' end (....................) |
In the following example, the RSET statement is used to assign the new value 'Page 12' to HEADING$. Sheerpower uses the current length of HEADING$, 20 characters, and replaces it with the new value, 'Page 12'. Sheerpower right-justifies this value by padding it with 13 leading spaces. Thus, HEADING$ still has a length of twenty characters.
Example 5-8 RSET Statement |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$; ')' rset heading$ = 'Page 12' print '('; heading$; ')' end (....................) ( Page 12) |
LSET str_var = str_expr |
Example 5-9 LSET Statement |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$; ')' lset heading$ = 'Page 12' print '('; heading$; ')' end (....................) (Page 12 ) |
LSET is used to left-justify string data.
When Sheerpower executes an LSET statement, it evaluates the string expression on the right side of the equal sign. Sheerpower assigns the new value to the string variable and left-justifies this value within the length of the old value. If the new value has leading or trailing spaces, these spaces are carried over and the string is justified with those spaces. LSET can be used only with strings.
RSET str_var = str_expr |
Example 5-10 RSET Statement |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$ ;')' rset heading$ = 'Page 12' print '(' ; heading$ ; ')' end (....................) ( Page 12) |
RSET is used to right-justify string data.
When Sheerpower executes the RSET statement, it evaluates the string expression on the right side of the equal sign. Sheerpower assigns the new value to the string variable and right-justifies this value within the length of the old value. If the new value has leading or trailing spaces, these spaces are carried over and the string is justified with those spaces. RSET can be used only with strings.
CSET str_var = str_expr |
Example 5-11 CSET Statement |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$; ')' cset heading$ = 'Page 12' print '('; heading$; ')' end (....................) ( Page 12 ) |
CSET is used to center string data.
When Sheerpower executes the CSET statement, it evaluates the expression on the right side of the equal sign. Next, Sheerpower assigns the new value to the string variable and centers it within the length of the old value. If the string value has leading or trailing spaces, the spaces are carried over and the string is centered with those spaces. CSET can be used only with strings.
LSET | RSET | CSET FILL str_expr: str_var = expr |
Example 5-12 LSET, RSET, CSET FILL Statements |
---|
heading$ = repeat$('.', 20) // Twenty dots print '('; heading$; ')' cset fill '*': heading$ = 'Page 12' print '('; heading$; ')' end (....................) (*******Page 12******) |
The value of expr is left-justified, right-justified or centered inside the str_var. The remaining part of the string is filled with the pattern specified by str_expr. If str_expr is the null string, no filling occurs---the remaining part of the string is left as is.
DATA [num_const | str_const] [,[num_const | str_const]...] . . . READ [num_var | str_var] [,[num_var | str_var]...] |
Example 5-13 DATA, READ, RESTORE Statements |
---|
dim months$(6) data January, February, March data April, May, June for i = 1 to 6 read months$(i) print months$(i) next i end January February March April May June |
DATA and READ statements are used to assign data to variables in cases where the data will not change with successive runs of the program.
The DATA and READ statements assign data to variables. DATA specifies a list of data to assign. The data must be given as constants and can be string, numeric or integer types. Multiple data items must be separated by commas.
The READ statement specifies a list of variables to assign data to. The variables can be string, numeric or integer variables. They can be substrings, array elements, etc.
When Sheerpower executes the first READ statement, it goes to the first DATA statement and assigns the items in the DATA list to the variables in the READ list. The first variable in the READ list is assigned the first value in the DATA list. The second variable in the READ list is assigned the second value in the DATA list, and so on.
DATA constant, constant, constant, constant... . . | | | | . READ variable, variable, variable, variable... |
If the data item contains a comma, the data item should be enclosed with single or double quotes. For example:
Example 5-14 DATA Items Containing Commas |
---|
dim amounts$(3) data '$25,000', '$250,000', '$2,500,000' read amounts$(1), amounts$(2), amounts$(3) print amounts$(1), amounts$(2), amounts$(3) end $25,000 $250,000 $2,500,000 |
The variable types and data types must match or an exception will result. For example, if the third item in the DATA list is a string constant, and the third variable in the READ list is a numeric variable, an exception will result.
When the second READ statement is executed, Sheerpower starts reading from the first unread data item in the DATA list. For example:
Example 5-15 DATA and READ Statements |
---|
dim months$(4) data January, February, March, April, May, June read months$(1), months$(2) read months$(3), months$(4) print months$(1), months$(2), months$(3), months$(4) end January February March April |
In the example above, when the first READ statement is executed, Sheerpower reads the months January and February. When the second READ statement is executed, Sheerpower will continue at the first unread month---March---and read it into months$(3).
If you attempt to read more data than what exists; that is, if your READ list has more items than your DATA list, an exception will result. You can avoid this by using the RESTORE statement to restore the DATA list and read from the beginning again.
The READ and DATA statements must occur in the same routine. For example, you cannot not have your DATA statements in the main logic area or in one routine and then have your matching READ statements in a different routine.
See Section 5.6.2 for information on using RESTORE.
Previous | Next | Contents | Index |