beautypg.com

Commands and functions – Xylem STORM 3 Basic Programming manual User Manual

Page 38

background image

36

COMMANDS AND FUNCTIONS

Declares the beginning of a SWITCH-CASE clause. The single variable given after the SWITCH

keyword specifies the character or characters to match. Once a CASE match is made, the program

will continue until a BREAK statement is seen, at which point the program will continue execution at

the END SWITCH statement. An optional DEFAULT route is followed if no other CASE statements

cause a match to occur.

var = 1

SWITCH var

CASE 0:

response$ = “Too low”

BREAK

CASE 1:

CASE 2:

response$ = “Low”

BREAK

CASE 3:

CASE 4:

response$ =”Mid”

BREAK

CASE 5:

CASE 6:

response$ = “High”

BREAK

DEFAULT:

response$ =”Unknown number”

END SWITCH

Declares a user-defined subroutine. Subroutines can specify and accept multiple parameters and

can return a number or string value using the RETURN statement. The END SUB statement marks

the end of a subroutine. Though not required, it is recommended that any subroutine returning a

string value should name routine with a trailing dollar-sign (“$”).

area$ = calc_area$(3, 4)

REM sets area$to 12

volume = calc_volume(3, 4, 5)

REM sets volume to 60

SUB calc_area$(h, w)

area = h * w

RETURN STR$(area)

END SUB

SUB calc_volume(h, w, d)

vol = h * w * d

RETURN vol

END SUB

SUB

SWITCH