Previous | Contents | Index |
The following are miscellaneous functions that Sheerpower performs:
With the DECODE function, given the string representation of a number and the base that the value is in (int_expr), Sheerpower returns the value in base 10. The number is returned as a real number. See also Section 6.4.13, ENCODE$(num_expr, num_int).
Example 6-188 DECODE Function |
---|
do line input 'Enter a HEX value', default 'ff': hex$ if _exit then exit do print 'Decimal value is'; decode(hex$,16) loop end Enter a HEX value? ff Decimal value is 255 Enter a HEX value? exit |
The DTYPE function returns as an integer value, the data type of an expression or object variable: 1 = string, 2 = integer, 3 = real. See Section 5.1, DECLARE for more on declaring variable data types.
Example 6-189 DTYPE Function |
---|
declare object x x = 45.6 print dtype(x) end 3 |
This function evaluates the expression described in str_expr and returns the result. If the variable being assigned the result is dynamic, the function puts the result in whatever data type the expression result was in. If the variable is NOT dynamic and the result is the wrong data type, a "Data type mismatch" error is returned.
Example 6-190 EVAL Function |
---|
line input 'Enter an expression': a$ print 'The result is '; eval(a$) end Enter an expression? 5 + 4 The result is 9 |
FALSE returns the constant 0. It is returned as an integer. See also "TRUE function".
Example 6-191 FALSE Function |
---|
input 'Enter your age': age of_age? = false if age >= 18 then of_age? = true print 'Given your age, you are '; if of_age? then print 'plenty old!' else print 'too young!' end Enter your age? 22 Given your age, you are plenty old! run Enter your age? 7 Given your age, you are too young! |
Given an array and a dimension number, this function returns the low bound for that dimension. The default dimension is 1.
Example 6-192 LBOUND Function |
---|
dim temperature(-40 to 100) print 'Lowest temperature we can handle: '; lbound(temperature,1) print 'Highest temperature we handle : '; ubound(temperature,1) end Lowest temperature we can handle: -40 Highest temperature we handle : 100 |
MAXNUM returns the largest number available in this implementation of Sheerpower.
Example 6-193 MAXNUM Function |
---|
print maxnum 9223372046854775807 |
SIZE returns the number of elements in one dimension of an array.
array-name | Array to examine | |
int-expr | Dimension to get the size of. The default dimension is 1. |
Example 6-194 SIZE Function |
---|
dim calendar(366) print 'Size of this calendar: '; size(calendar) Size of this calendar: 366 |
TRUE returns the constant 1. It is returned as an integer. See also "FALSE" function.
Example 6-195 TRUE Function |
---|
input 'Enter your age': age of_age? = false if age >= 18 then of_age? = true print 'Given your age, you are '; if of_age? then print 'plenty old!' else print 'too young!' end Enter your age? 38 Given your age, you are plenty old! rnh Enter your age? 5 Given your age, you are too young! |
Given an array and a dimension number, UBOUND returns the upper bound for that dimension. It returns an integer value. The default dimension is 1.
Example 6-196 UBOUND Function |
---|
dim temperature(-40 to 100) print 'Lowest temperature we can handle: '; lbound(temperature,1) print 'Highest temperature we handle : '; ubound(temperature,1) end Lowest temperature we can handle: -40 Highest temperature we handle : 100 |
The PRINT statement prints or displays text on the screen. The printed text can be formatted using a mask or directive and/or highlighted using video options. This section describes the various ways that text can be displayed on the screen.
PRINT [[AT row, col] [,ERASE] [,WIDE] [,BLINK] [,REVERSE] [,BOLD] [,USING "print_mask"]:] expr [{, | ;} expr...] [, | ;] |
Example 7-1 PRINT Statement |
---|
input name$ print 'Hello, '; name$ print bold: 'Here is a number: 1.93' end ? Rick Hello, Rick Here is a number: 1.93 |
The simplest version of the PRINT statement is:
PRINT expr |
expr is an expression to print. expr can be any Sheerpower expression. Sheerpower prints the value of the expression at the current cursor position and then generates a new line. A PRINT statement without an expression simply generates a new line.
Example 7-2 Print Expression |
---|
print 'Line 1' print print 'Line 3' end Line 1 Line 3 |
One PRINT statement can print several items. Multiple items must be separated with a comma or a semicolon. The separator determines where the next expression will be printed.
Two additional features can be used to position the cursor:
Separating print items with a semicolon causes the items to immediately follow one another. When the items are printed, no spaces appear between the expressions.
Example 7-3 Semicolon in PRINT Statement |
---|
alpha$ = 'ABCDEFGHIJKLM' bet$ = 'NOPQRSTUVWXYZ' print alpha$; bet$ end ABCDEFGHIJKLMNOPQRSTUVWXYZ |
Print in columns by using print zones. Each print zone has a default width of twenty characters. To change the width, see Section 11.17.2, SET ZONEWIDTH.
|-------------------|-------------------|-------------------| 1 20 40 60 |
Separating items with a comma causes the item following the comma to be printed in a new print zone. The terminal width determines the number of zones in each line. (See Section 11.9.1, ASK MARGIN statement to determine the terminal width.)
Example 7-4 Commas and Print Zones |
---|
input name_1$, name_2$ print name_1$, 'MARY', name_2$ end ? FRED, JOHN <------ type in FRED, JOHN FRED MARY JOHN |
If an item is longer than the zone width, Sheerpower continues it into the next print zone. Sheerpower uses as many print zones as necessary to print an item.
? FRED, DILLENSCHNEIDER & SONS FRED MARY DILLENSCHNEIDER & SONS |
Sheerpower writes data sequentially. If an item is too long (over 132 characters) to write in one record, Sheerpower continues it in the next record.
Example 7-5 Printing Long Data in Records |
---|
open #1: name 'test.txt', access output set #1: margin 80 print #1: repeat$('+-', 70) close #1 open #1: name 'test.txt', access input line input #1: record_1$, record_2$ print 'Record 1: '; record_1$ print 'Record 2: '; record_2$ close #1 end Record 1: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Record 2: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
Previous | Next | Contents | Index |