| Previous | Contents | Index |
OPTION BASE [0 | 1]
|
OPTION BASE sets the lowest subscript or base for arrays. The base can be either zero or one. If you use OPTION BASE 0, the lowest element of an array has the subscript zero (0). If you use OPTION BASE 1, the lowest element is subscript one (1).
See Section 5.8.4 for an example and detailed information on this statement.
[LET] var = expr
|
| Example 5-5 LET statement |
|---|
input 'Last name': last$ input 'First name': first$ let name$ = first$ & ' ' & last$ print name$ end Last name? Taylor First name? Rick Rick Taylor |
The LET statement is used to store information into a variable or data structure.
var is the variable being assigned a value. expr is an expression. The expression is evaluated and its result is assigned to the variable. The expression can be any SheerPower expression (see Chapter 4.) The variable and the expression data types must match. For instance, if var is a string variable, expr must be a string expression.
NOTE: The keyword LET is optional. For example:
LET name$ = first$ & ' ' & last$
|
can be stated as:
name$ = first$ & ' ' & last$
|
When SheerPower executes the LET statement, it first evaluates the expression on the right side of the equal sign. It then assigns this value to the variable on the left side of the equal sign. The variable represents a location in memory. The value of the expression is stored in this location. Each time a new value is assigned, the old value is lost and the new value is stored in its memory location.
Assigning numeric values:
| Example 5-6 Assigning numeric values with LET statement |
|---|
input 'Amount': amount let rounded% = amount print 'Real numeric amount:'; amount print 'Integer amount (after rounding):'; rounded% end Amount? 1.54 Real numeric amount: 1.54 Integer amount (after rounding): 2 |
num_var++
|
It is common place to increment a numeric variable:
total = total + 1 lines = lines + 1 |
SheerPower 4GL 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]...]
|
| Previous | Next | Contents | Index |