NotesDocumentArray
While working on a R4.6 application I needed a flexible document container that would allow me to add and remove documents on an ad hoc basis, sort the documents based on an item value. So here's my solution: The NotesDocumentArray class.
Description:
With it you can:
- add and remove individual documents and add document collections
- sort by an item value
- set an item value across all documents in the array
- remove documents from the array where item = value
- merge document arrays together
- It also has standard NotesDocumentCollection methods like GetFirstDocument, GetNthDocument(x) and GetNextDocument(doc)
Some of the functionality of this class can be recreated manually with an array of NotesDocuments but then you have to worry about Redimming and all that hassle, which is boring. Use the NotesDocumentArray class and you can just call the AddDocument method or the AddCollection method and the class worries about all that for you and you get a bunch of other cool methods to boot! Doesn't that sound good?
Please read the description in the code comments as well.
I mentioned ND 4.6 but it's also usful in R5. For example you can't dim a NotesDocumentCollection the call AddDocument to add the first document; the collection already has to contain something. This is annoying if you don't want it to contain anything! The NotesDocumentArray is initialised as empty, ready for you to start adding stuff.
Properties and Methods
here's a complete list:
Public Property Get Count As Integer
'// Returns the number of documents in the array
Public Property Get IsSorted As Integer
'// Returns true or false if the array has been sorted
Public Property Get SortedBy As String
'// Returns the item name by which the array was sorted
Public Property Get GetFirstDocument As NotesDocument
'// Returns first document in array
Public Property Get GetLastDocument As NotesDocumenty
'// Returns last document in array
Public Property Get GetNthDocument(x As Integer) As NotesDocument
'// Returns document at index <x>
Public Property Get GetDocumentIndex(doc As NotesDocument) As Integer
'// Returns document index number or 0 if not found
Public Property Get GetNextDocument(doc As NotesDocument) As NotesDocument
'// Returns next document sfter supplied docs index otherwise nothing if there's no next doc
Public Property Get GetPrevDocument(doc As NotesDocument) As NotesDocument
'// Returns previous document before supplied docs index otherwise nothing if there's no prev doc
Public Sub New ()
'// Class New constructor
Public Sub Reset()
'// resets the doc array to empty
Public Sub AddArray(array2 As NotesDocumentArray)
'// Add another notes document array to the array
Public Sub AddCollection(dc As NotesDocumentCollection)
'// Add a notes document collection to the array
Public Sub AddDocument(doc As NotesDocument)
'// Add a document to the array
Public Sub RemoveDocument(doc As NotesDocument)
'// Remove a document from the array
Public Sub RemoveMatchingDocuments(itemname As String, text As String)
'// Removes all documents where item.text = text
Public Sub SortBy(itemname As String)
'// Sorts documents by the value contained in the item specified by item name
Public Sub SetFieldValue(itemname As String,itemvalue As Variant)
'// sets a specified field to a specified value in all docs in array
Status
This is still a beta version so any suggestions/comments/corrections/additions are most welcome