SET ... END SET statement
Purpose: Akin to the
DIM
statement, SET
gives you a convenient means of declaring and loading Array variables
in one easy statement.
SET
supports LOCAL and GLOBAL contexts. If
SET
is used inside a SUB/FUNCTION then the variable and
its data is implicitly local in scope.
Note well ! The OPTION BASE
statement does not work with the arrays generated with the
SET
statement.
Syntax: SET VArray[] AS data type Comma, delimited, values, list END SET Parameters:
|
Remarks:
SET processing allows BCX keywords to be recognized, for example,
SET KeyTable[] AS ACCEL FCONTROL|FVIRTKEY, ASC("F"), IDM_FIND, FCONTROL|FVIRTKEY, ASC("R"), IDM_REPLACE END SET
When a partial initalization is being done, braces { } are used to delimit the parts of the SET to be initialized. For example,
TYPE foo A AS INTEGER B AS INTEGER C AS BYTE END TYPE SET MyFoo[] AS foo {12,13}, {19,20} END SET
would initialize as:
MyFoo[0].A = 12 MyFoo[0].B = 13 MyFoo[0].C = NOT initialized MyFoo[1].A = 19 MyFoo[1].B = 20 MyFoo[1].C = NOT initialized
SHAREDSET ... END SET statement
SHAREDSET
can be used instead of
SET
. If SHAREDSET
is used the code generated does not have the static storage class qualifier
that is generated with SET
.
SHAREDSET
allows data to be shared across multiple files.
Syntax: SHAREDSET VArray[] AS data type Comma, delimited, values, list END SET Parameters:
|
Remarks:
SHAREDSET processing allows BCX keywords to be recognized, for example,
SHAREDSET(PTR CC[3])(LPSTR) AS LPSTR UCASE$, MCASE$, LCASE$ END SET
Here are some examples using
SET
.
Instead of coding this:
DIM A[6] AS DOUBLE A[0] = 1.1 A[1] = 5.5 A[2] = 9.9 A[3] = 3.3 A[4] = 10.1 A[5] = 4.41
Do this instead! The size of the array is automatically calculated.
SET A[] AS DOUBLE 1.1, 5.5, 9.9, 3.3, 10.1, 4.4 END SET
Here's another example using strings
SET B$[3] "apples", "oranges", "bananas" END SET
which is the same as
DIM B$[3] B$[0] = "apples" B$[1] = "oranges" B$[2] = "bananas"
The example below demonstrates SET
in a subroutine.
TEST() SUB TEST() SET b$[10,1024] "one" , "two", "three", "four", "five", "six", "seven", "eight" END SET PRINT b$[0] PRINT b$[1] PRINT b$[2] PRINT b$[3] PRINT b$[4] PRINT b$[5] PRINT b$[6] PRINT b$[7] END SUB
Here is an example of SET
with comments.
SET C[16] AS COLORREF 16777215, 'white 16776960, 'cyan 16711935, 'pink 16711680, 'blue 65535, 'yellow 65280, 'green 255, 'red 12632256, 'lightgray 8421504, 'darkgray 8421376, 'darkcyan 8388736, 'darkpink 8388608, 'darkblue 32896, 'brown 32768, 'darkgreen 128, 'darkred 0 'black END SET
Here is an example using pointers.
SET errmsg[] AS CHAR PTR "Overflow", "Division by zero", "etc", "etc" END SET DIM i FOR i = 0 TO 3 ? "Error ";i;" ";errmsg$[i] NEXT getchar();
Here is how to use SET
to read mixed type data which needs to be modified at run-time.
TYPE GameData s$ x1, y1, z1, x2, y2, z2 u v END TYPE SET GD[] AS GameData "outside a house",1,0,0,1,0,0,0,0, "by a window",0,1,0,0,0,0,1,0 END SET PRINT GD[0].s$ PRINT GD[0].x1 GD[0].s$ = "Inside the door" GD[0].x1 = 345 PRINT GD[0].s$ PRINT GD[0].x1 PRINT GD[1].s$ PRINT GD[1].x1 PAUSE
BCX Console Sample Programs using SET
function.