Working with Dynamic Arrays
Dynamic arrays are used to store a relatively boundless number of array elements. Using dynamic arrays, you can adjust the total number of elements stored in the array (as opposed to a fixed maximum).
How It Works
Using the Redim statement in conjunction with the Preserve parameter, you can dynamically allocate and resize the storage space needed for an array. The Redim statement is used to redefine the number of elements in the array. The Preserve parameter keeps (or preserves) all existing element values as the array size is increased. The Redim statement is often used with loops or the Ubound function (which determines the upperboundary of the array) to increment or decrement the size of the array.
Implementation
To implement this solution, a loop is used to create the initial array of elements. On the first pass, the array is established, and the first value is assigned. During the following passes, the Preserve parameter is used to retain previous array element values and append values to the array. Using the Ubound function, the upper boundary of the array is identified and incremented (but could also be decremented) and new elements are appended to the array while the previous values are preserved.
Sub Click(Source As Button) Dim w As New NotesUIWorkspace Dim s As New NotesSession Dim db As NotesDatabase Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim counter As Integer Set w = New NotesUIWorkspace Set s = New NotesSession Set db = s.CurrentDatabase Set uidoc = w.CurrentDocument Set doc = uidoc.Document '---------------------------------------------------- ' Add elements to array for illustration purposes '---------------------------------------------------- For counter = 0 To 3 If counter = 0 Then Redim myList(0) As String myList (counter) = "Element " & counter Else Redim Preserve myList(counter) As String myList(counter) = "Element " & counter End If Next '---------------------------------------------------- ' Display initial array '---------------------------------------------------- Msgbox Implode(myList, ", "), , "Array 1" '---------------------------------------------------- 'Dynamically add an element to the array '---------------------------------------------------- counter = Ubound (myList) +1 Redim Preserve myList(counter) As String myList(counter) = "Element " & counter '---------------------------------------------------- ' Display dynamic array '---------------------------------------------------- Msgbox Implode(myList, ", "), , "Array 2" '---------------------------------------------------- ' Assign array to an arbitrary field for illustration '---------------------------------------------------- doc.FIELD = myList End Sub
Create a Custom Popup Dialog Box
|