SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

5.4.2 LSET

FORMAT:


        LSET str_var = str_expr 

EXAMPLE:

Example 5-9 LSET statement

  heading$ = repeat$('.', 20)          // Twenty dots 
  print '('; heading$; ')' 
  lset heading$ = 'Page 12' 
  print '('; heading$; ')' 
  end
  
 
(....................) 
(Page 12             ) 

PURPOSE:

LSET is used to left-justify string data.

DESCRIPTION:

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.

5.4.3 RSET

FORMAT:


        RSET str_var = str_expr 

EXAMPLE:

Example 5-10 RSET statement

  heading$ = repeat$('.', 20)          // Twenty dots 
  print '('; heading$ ;')' 
  rset heading$ = 'Page 12' 
  print '(' ; heading$ ; ')' 
  end
 
 
(....................) 
(             Page 12) 

PURPOSE:

RSET is used to right-justify string data.

DESCRIPTION:

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.

5.4.4 CSET

FORMAT:


        CSET str_var = str_expr 

EXAMPLE:

Example 5-11 CSET statement

  heading$ = repeat$('.', 20)          // Twenty dots 
  print '('; heading$; ')' 
  cset heading$ = 'Page 12' 
  print '('; heading$; ')' 
  end
 
 
(....................) 
(       Page 12      ) 

PURPOSE:

CSET is used to center string data.

DESCRIPTION:

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.

5.5 LSET, RSET, CSET FILL

FORMAT:


        LSET | RSET | CSET FILL str_expr: str_var = expr 

EXAMPLE:

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******) 

DESCRIPTION:

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.

5.6 DATA, READ, RESTORE statements

5.6.1 READ

FORMAT:


        DATA [num_const | str_const] [,[num_const | str_const]...] 
                      . 
                      . 
                      . 
        READ [num_var | str_var] [,[num_var | str_var]...] 

EXAMPLE:

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 

PURPOSE:

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.

DESCRIPTION:

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 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 program unit. For example, you cannot not have your DATA statements in the main program unit and your matching READ statements in a subprogram.

See Section 5.6.2 for information on using RESTORE.

5.6.2 RESTORE

FORMAT:


        RESTORE 

EXAMPLE:

Example 5-16 RESTORE statement

  dim months$(3) 
  dim more_months$(3) 
  data January, February, March 
  for i = 1 to 3 
    read months$(i) 
    print months$(i) 
  next i 
  restore
  print
  for i = 1 to 3 
    read more_months$(i) 
    print more_months$(i) 
  next i 
  end 
 
 
January 
February 
March 
 
January 
February 
March 

PURPOSE:

RESTORE is used to access the same set of data (from a DATA statement) for a number of READ statements.

DESCRIPTION:

RESTORE restores the DATA statements in a program unit so they can be used again. When the RESTORE statement is executed, all the DATA statements which have been read are restored. The next READ statement causes SheerPower to go back to the first DATA statement and begin assigning the items in its list.

In the example program, the months will be read and assigned to the array MONTHS$. When the RESTORE is executed, the DATA statements will be restored. When the READ statement is executed, the months will be read into the new array MORE_MONTHS$.

5.7 Private Variables in Routines

FORMAT:


    ROUTINE routine_name: PRIVATE var, var, var, ... 
or 
    ROUTINE routine_name: PRIVATE INTEGER var, STRING var, STRING var, ... 


Previous Next Contents Index