Programming Concept Competencies
Questions derived from the 737 – IBM Lotus Notes Domino 7 Using LotusScript in IBM Lotus Domino 7 Applications Self Test Software Practice Test.
Objective: Programming Concept Competencies
SubObjective: Using LotusScript features in Domino – Using fixed arrays
Item Number: 718.104.22.168
Single Answer, Multiple Choice
Consider the following code:
Dim myArray(1 To 3) As String ‘Line1
Dim message As String
For x = Lbound(myArray) To Ubound(myArray) ‘Line3
What will this code produce?
- The message “ABC” will be displayed.
- A compile error will be generated for Line1.
- A compile error will be generated for Line2.
- It will return the runtime error “Subscript out of range.”
D. It will return the runtime error “Subscript out of range.”
An array is a collection of elements/objects that are of the same data type. Each element in an array is accessed by its position within the array via an index/subscript. Arrays can be either fixed or dynamic and can be either single or multiple dimensions.
The size of a fixed array is defined when the array is declared in a Dim statement by denoting the number of elements within parentheses. The size of a fixed array cannot be changed.
The size of a dynamic array is not declared until runtime. The Dim statement of a dynamic array uses empty parentheses. A ReDim statement is then used to provide the number of elements in the dynamic array. This enables the size of the dynamic array to change during runtime.
The size of an array, defined in a Dim or ReDim statement, based on an offset from the lower bound of the array. By default, the lower bound is 0 (zero). However, this lower bound can be changed to either an “Option Base” statement or by providing an explicit lower bound in the Dim or ReDim statement. The Option Base may be defined as either 0 or 1 (with 0 as the default). The Option Base statement applies to all arrays in a module. A single array can be defined with a different lower bound by defining the lower and upper bound in the declaration of the array. For example a five-element array of Strings may be defined in either of these ways (assume that the Option Base is using the default of 0):
Dim myArray(4) As String
Dim myArray(1 To 5) As String
The function LBound returns the lower bound of an array. For example: “firstElement = LBound(myArray)”. The function UBound returns the upper bound of an array. For example: “totalElements = UBound(myArray)”.
An array may have up to eight dimensions. A single dimension array uses only one subscript to define and access its elements.
For example, the statement “Dim myArray(4) As String” defines a single dimension String array consisting of five elements. The statement “x = myArray(2)” would return the third element to the variable “x”.
Another example, the statement “Dim myArray(9, 1) As String” defines a two-dimension String array consisting of 10 elements in the first dimension of the array, and two elements within each of the elements in the first dimension. The statement “x = myArray(7, 0)” would return the first element within the eighth element of first dimension of the array to the variable “x”.
The ReDim statement can be used at any time to change the size of an array that was declared as a dynamic array. If the “Preserve” keyword is not used in the ReDim statement, the array will be re-initialized to the default values for the data type. If a dynamic array is resized to include more elements, you must use the “Preserve” keyword to retain the current values in the array.
1. Domino Designer 7 Help – search on: Fixed arrays
2. Programming Guide Volume 2 – LotusScript/COM/OLE Classes – Chapters 1 and 2 http://doc.notes.net/uafiles.nsf/docs/DESIGNER70/$File/prog2.pdf