I am trying to build a list with tags and values but my values are not appending to the list (like an array)… What am I doing wrong? Please help!
Sub Initialize
Dim session As New NotesSession
Dim curDb As NotesDatabase
Dim curView As NotesView
Dim curDoc As NotesDocument
Dim myList List As Variant
Dim newValue As String
Dim newTag As String
Dim reportView As NotesView
Dim reportDoc As NotesDocument
Dim reportDc As NotesDocumentCollection
Set curDb = session.CurrentDatabase
Set curView = curDb.GetView( "All" )
Set curDoc = curView.GetFirstDocument
Set reportView = session.CurrentDatabase.GetView( "Lookup" )
Set reportDoc = reportView.GetFirstDocument
While Not curDoc Is Nothing
keys = curDoc.UNID
Set reportDc = reportView.GetAllDocumentsByKey( keys , True )
If reportDC.count = 0 Then
If curDoc.SType(0) = "Corporation" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Corp(0)
Else
If curDoc.SType(0) = "Association" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Assoc(0)
End If
End If
myList(newTag$) = newValue$
End If
Set curDoc = curView.GetNextDocument( curDoc )
Wend
Print myList(newTag$)
End Sub
Subject: Newbie Working with Lists
Have you used the debugger to see what is happening?
Looking at your code here are some thoughts on POSSIBLE problems, in red. Debugging would help us narrow it down:
Set reportView = session.CurrentDatabase.GetView( "Lookup" )
Consider adding, incase the view is not found.
if Not reportView is Nothing Then
Set reportDoc = reportView.GetFirstDocument
While Not curDoc Is Nothing
keys = curDoc.UNID
Set reportDc = reportView.GetAllDocumentsByKey( keys , True )
Maybe your DC has 0 elements always? Confirm this, maybe the view is not sorted.
If reportDC.count = 0 Then
If curDoc.SType(0) = "Corporation" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Corp(0)
Else
If curDoc.SType(0) = "Association" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Assoc(0)
End If
End If
What happens when curDoc.SType is not Corporate or Association? newTag and NewValue will not be assigned, therefore they will have the last values.
You could change the above nested code in blue to as follows:
If curDoc.SType(0) = "Corporation" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Corp(0)
ElseIf curDoc.SType(0) = "Association" Then
newTag$ =curDoc.Owner(0)
newValue$ =curDoc.Assoc(0)
ELSE
What in this case?
End If
myList(newTag$) = newValue$
End If
Set curDoc = curView.GetNextDocument( curDoc )
Wend
End if
There are a couple of things to check.
Subject: RE: Newbie Working with Lists
Thanks for your suggestions. I will implement them. However, I mainly need to figure out how to create a list with multiple values. I have stepped thru the debugger and I know that the values are getting set… however, they are I don’t have a list of values, instead the values are being replaced. Should I be doing a forall to get multiple values?
Thanks for your assistance!
Subject: RE: Newbie Working with Lists
Assuming you’re getting a different key each time, your values are being added to the list, not replaced. Can’t you see the value of the list in the debugger?
Naturally, your Print statement will only display one value because you specified a particular key. Print can’t display the value of a whole list – it needs a string argument or something that can be converted to a string. The DebugStr function might be useful to you if you can’t tell from the debugger whether you have correct values – but I think you should be able to tell from the debugger.
Subject: RE: Newbie Working with Lists
Yes, I am getting a different keys… so how do I see the full list?.. When I debug I see the tags and values but they don’t have mulitple values. How can I capture the entire list of values in myList?
Subject: RE: Newbie Working with Lists
Each tag can have only one value. That value, though, can be an array, or a splittable string ("value1^^value2^^value3).
Subject: RE: Newbie Working with Lists
Ok, I think I am beginning to understand. So if I only have 3 owners (tags) I can get an array or list of corp./assoc. names for each of those owners. My list can be 1000s of names. I still don’t understand how I can view or print the entire myList . i.e. Can I print myList with all it’s values and tags?
Subject: RE: Newbie Working with Lists
Ah, now we come to a better question. There’s no useful way to print raw data – you need to create a printable entity of some sort. In this case, you already have a viewable/printable option at hand without a lot of coding – a view or folder would have done the trick, if it was categorized on the Owner. If you need something a bit more “portable”, you could create a spreadsheet or CSV file from the data in the list.
The trick to getting a good answer here is to include what you are trying to accomplish in plain language, not just what you are currently doing. There may be a much easier way to go about things, or you may be headed down a side road that will have lots of lovely scenery, but will not take you where you want to go.
So – what is the real goal here?
Subject: RE: Newbie Working with Lists
Whew… Thanks Stan. The goal here is to create a reportfor mgmt. that shows all the assoc./ corp. that don’t have a matching report on the reportview (based on key). That’s it!
Subject: RE: Newbie Working with Lists
forall elements in myList
myTag = listtag(elements)
print "Element with tag " & myTag & " is " & elements
end forall
Hope this helps. Lists are great, I love them. The next step will be to create your own custom classes, so you can store collections of multiple “things” with lots of different values.
Here is a great article on lists if you’re interested…
http://www.billbuchan.com/web.nsf/htdocs/BBUN67JJCV.htm