23 of 158
17 Option Base 1 ... Dim ival(5) as Integer This defines an array of Integer values with 5 elements. The lower bound is 1 and the upper bound is 5. The lower bound may be explicitly specified as well. The second example below illustrates the use of a negative value as one of the bounds. Note that the upper bound must be greater than or equal to the lower bound. Public pulseCount(1 to 6) as Byte Private itemData(-3 to 45, 1 to 4) as Boolean You may also define an array of strings but only when Option AllocStr is in effect as it is by default. Dim msg(1 To 4) as String BasicX Compatibility Note In BasicX mode, each array dimension must have at least two elements. Also, arrays of type String are not supported. There is no checking, either at compile time or at run time, for array index underflow or overflow. If you write code that uses an index outside of the defined range of indices, the results are undefined. Defining Subroutines A subroutine is a collection of statements that can be executed by using the subroutine name in a Call statement. The advantage of creating subroutines is that we can think of them as logical blocks instead of thinking about all of the details that are dealt with by the statements within the subroutine. A subroutine may be defined as taking zero or more parameters. If it has parameters defined, you must supply a value for each of the parameters when you invoke the subroutine using the Call statement. The syntax for defining a subroutine is shown below. [Public | Private] Sub <name> ( [<parameter-list>] ) [<statements>] End Sub If neither Public nor Private is specified, Public is assumed. The <parameter-list> consists of zero or more parameter specifications, each separated from the next by a comma. Note that the parentheses are required even when there are no parameters. The parameters given in the subroutine’s definition are called the “formal parameters”. The parameters that appear in each invocation of the subroutine are referred to as the “actual parameters”. The syntax for a formal parameter specification is: [ByVal | ByRef] <name> As <type> The <name> element is the name by which the passed parameter is known within the subroutine. The <type> element is one of the fundamental types listed in the table in Section 2.2. You may also specify a default value for a parameter, a topic that is discussed in more detail in Section 3.20.