I’m trying to build an array by adding values from a number of selected documents. When I step through the code and watch the debugger I can SEE the array getting filled in with values from each document. But when I try to output the contents I get null. I’ve added a Print line and it outputs nothing.
Here is the code:
Set collection = db.UnprocessedDocuments
iCount = collection.Count
Redim varUnlinked(iCount-1) As Variant
Set doc = collection.getFirstDocument()
i=0
Do Until doc Is Nothing
varUnlinked(i) = doc.GetItemValue("ProjectRef")
Print varUnlinked(i)
i = i +1
Set doc = collection.getNextDocument(doc)
Loop
I’m not sure why you’re using Variant as the DataType for your array,… Search the Designer help for “Dynamic Array” there’s an article there with examples of how they do it.
Edit: I thought of this code… test it and let me know if that works:
Dim iCount as Integer
Dim counter as Integer
Dim varUnlinked as String
Set collection = db.UnprocessedDocuments
iCount = collection.Count
Redim varUnlinked(iCount)
For i = 1 to iCount
Set doc = collection.GetNthDocument(i)
varUnlinked(i) = doc.GetItemValue("ProjectRef")
Print varUnlinked(i)
Sorry, I had a % after iCount that I removed… try to copy/paste the code again.
Also I showed the Dim statement for the variables I’m using in the code, but not what you were using outside of it… make sure you declared every datatype properly. I can’t see it cause you didn’t paste the whole code.
I found the problem. GetItemValue returns an Array, so I was trying to load my varUnLinked array with another array. I fixed it by extracting the value of the array before loading my varUnlinked array. Here is the working code:
Sub Initialize
Dim session As New NotesSession
Dim collection As NotesDocumentCollection
Dim db As NotesDatabase, doc As NotesDocument
Dim i As Integer, iCount As Integer
Dim varUnlinked() As Variant , vProjRef As Variant
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
iCount = collection.Count
If iCount <=1 Then
Msgbox "You must select 2 or more Projects to create Linking",0,"Error"
Exit Sub
Else
Set doc = collection.getFirstDocument()
Redim varUnlinked(iCount-1)
i=0
Do Until doc Is Nothing
vProjRef = doc.GetItemValue("ProjectRef")
varUnlinked(i) = vProjRef(0)
i = i +1
Set doc = collection.getNextDocument(doc)
Loop
End If
i=0
For i =0 To Ubound(varUnlinked)
Print varUnlinked(i)
Next