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 |
An Introduction to the Lotus Domino Tool Suite
Getting Started with Designer
Navigating the Domino Designer Workspace
Domino Design Elements
An Introduction to Formula Language
An Introduction to LotusScript
Fundamentals of a Notes Application
Calendar Applications
Collaborative Applications
Reference Library Applications
Workflow Applications
Web Applications
Design Enhancements Using LotusScript
Design Enhancements Using Formula Language
View Enhancements
Sample Agents
Miscellaneous Enhancements and Tips for Domino Databases
Data Management
Security
Application Deployment and Maintenance
Troubleshooting
Appendix A. Online Project Files and Sample Applications
Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?