Lookup Contacts using a listbox

thartung

New Member
Licensed User
:sign0104:
I am trying to learn how to create a listbox that is populated by the PIM contacts, and being a noob, I am a bit confused. I have found some examples that show how to add the contacts collection and so forth, but I am not sure how to extact the selected item in the list. So far this is what I have:

form2.show
sendlist.New1
ContactsCollection.New1("Contacts")
ContactsCollection.SortItems("LastName",false) 'sorts the contacts using the last name field.
For i = 0 To ContactsCollection.Count - 1
Contact.Value = ContactsCollection.GetItem(i)
listbox1.Add(Contact.LastName & " " & Contact.firstName) 'Add the contact's first and last name to ListBox1.
Next
Contact.Value = ContactsCollection.GetItem(listbox1.SelectedIndex)

It errors out on the last line. Error says object reference not set

Thank you for any help provided:confused:
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
This might help, I did it for someone else asking a very similar question.
It only shows contacts that have a mobile number listed.
Modify it to your own needs,

PS don't forget to add the Outlook.dll's to the working directory.

Regards,
RandomCoder
 

Attachments

  • PIM Collection.sbp
    1.7 KB · Views: 190

thartung

New Member
Licensed User
Thank you for the code. I loaded it on my device making sure the outlook.dll was in the working directory. When I run it on my device the listbox "Select Name" and "Mobile Number" are blank. No errors, but I would have expected to see a list of my contacts with a mobile number. I realize when running on the desktop they would be blank because of the "dummy" dll, but shouldn't I see something on the device?:confused:
 

thartung

New Member
Licensed User
I just thought..... I have basic4PPC and all my sample code on my storage card. Could this be a problem?? I have been able to successfully run other samples
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm sorry to hear that you had problems with the code.
Is it possible that you have a blank entry within your contacts?
Because the listbox is set to a height of only one entry, it may be that the box is populated but just showing the blank entry, try scrolling down.
As it didn't error I would guess that it is working, you could also try making the listbox larger.

Regards,
RandomCoder
 

thartung

New Member
Licensed User
Thank you for the code Erel. This snippet works, yet the example that RandomCoder provided still doesn't seem to show any contacts even after I made the listbox larger. Not a big deal. I appreciate the time both of you spent helping me.

Thanks again!!
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Sorry for the confusion caused, but I did state that it selects only contacts having a mobile number.
If loading all contacts regardless of the contact details then there is no need to keep track of the index as this will be unaltered.

Regards,
RandomCoder
 
Top