08-04-2009 06:31 AM
There is an example in the SDK regarding GetContactsByID (very end of post). I am trying this, but I want to populate the Guid in a loop. However, I am getting the following error in the loop:
Warning 4 Variable 'cGuidKeys' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Users\Owner\...\Class1.vb
A snippet of my code follows, thanks for any assistance, I hope this is a simple issue.
[Part of] my code:
Dim cGuidKeys() As Guid Dim i As Integer 'get activities code is here, including this line: 'Dim aContactList As ActivityContactCollection = activity.GetActivityContactsFromDB() For i = 0 To aContactList.Count - 1 cGuidKeys(i) = aContactList.Item(i).Key Next i 'show stuff is here
cGuidKeys(i) is underlined with the green squiggly in VB, and shows the error. I *can* populate one Guid by specifying:
cGuidKeys(0) = aContactList.Item(0).Key
but again, I'd like to loop through the list.
'Example 3 'This example populates a ContactList with the first five contacts of another ContactList. Dim cList As ContactList Dim cList5 As ContactList Dim contactKeys(5) As Guid Dim i As Integer 'Get a list of contacts cList = ActFwk.Contacts.GetContacts(Nothing) 'Add the first 5 contacts of second ContactList. For i = 0 To 4 contactKeys(i) = cList(i).ID Next i cList5 = ActFwk.Contacts.GetContactsByID(Nothing, contactKeys) 'Display how many contacts were added to the ContactList. If (cList5.Count > 0) Then MessageBox.Show(cList5.Count.ToString()) Else MessageBox.Show("The ContactList was empty.") End If
08-05-2009 01:27 AM
I don't have intelliesense to hand so it may be slightly wrong but basically you can create an arraylist and thenadd to that. Then just convert the arraylist to an array at the end......
Dim cGuidKeys as New ArrayList
Dim i As Integer
'get activities code is here, including this line:
'Dim aContactList As ActivityContactCollection = activity.GetActivityContactsFromDB()
For i = 0 To aContactList.Count - 1
'assuming you have a ref to the act application as actapp....
08-05-2009 10:21 PM
Thanks, the line:
was what was missing. I don't have a full grasp on all the ins and outs of VB yet, so this helped immensely. Thanks again...