Contacts and List Boxes

Oran

Member
Licensed User
Okay,

I'm a newbie here. I've done some searching on the forum and have not quite found the answer that I am looking for.

Here is what I want to accomplish.

1. I have 2 list boxes on my form.
2. When I Load the form, I want ListBox1 to display all PIM Contacts that have a mobile number and omit any that do not.
3. When I click/tap on an entry in ListBox1, ListBox2 will display a list of mobile numbers associated with the ListBox1 selection.
4. When I click/tap on the entry in ListBox2 that I want, I want to grab that phone number and assign it to a variable so that it can be written into a file or registry entry for later use.

Here is the code I am using so far:

LIST BOX 1
-------------------------------------------------
Sub cboButtons_SelectionChanged (Index, Value)
Dim MTL
Contact.New1
PimCol.New1("Contacts")
ListNumbers.Clear
ListContacts.Clear
For I = 0 To PimCol.Count -1
Contact.Value = PimCol.GetItem(I)
MTL = StrLength(Contact.MobileTelephoneNumber)
If MTL > 0 Then
ListContacts.Add(Contact.Nickname & "-" & Contact.LastName & "," & Contact.FirstName)
End If
Next
ListContacts.Refresh
End Sub

LIST BOX 2
------------------------------------------
Sub ListContacts_SelectionChanged (Index, Value)
Contact.New1
PimCol.New1("Contacts")
PimCol.GetItem(ListContacts.SelectedIndex)
ListNumbers.Clear
Contact.Value = PimCol.GetItem(ListContacts.SelectedIndex)
ListNumbers.Add (ListContacts.SelectedIndex & "/" & Contact.LastName & "/" & Contact.MobileTelephoneNumber)
ListNumbers.Refresh
End Sub


I could really use some help.

Thanks

Dave ///
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi Oran,

For ListBox 2 I don't think that you need to create a new instance of Contacts and PimCol as they have already been created when you did ListBox 1.
Try removing these two lines and see what happens.


PS Welcome to the Forum :)

Regards,
RandomCoder
 

Oran

Member
Licensed User
RandomCoder,

Thanks for the blisteringly fast reply! I zapped the two entries you suggested and the list boxes still appear to be out of sync with each other. List2 appears to be 'behind' list 1 in the index or something.... really wierd.

PS - Thanks for the warm welcome. I really love this OS language -- puts eVB to shame -- really simple to understand and use. Slight syntax shift from my normal vb use but WAY better than the competition out there.

Dave ///
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Sorry for the delay, I'm now at work and can only assist during break times.
You say that the problem is that your numbers are out of sync with the names?

This might be caused by having contact names in the list that do not have numbers associated with them.
I'd be inclined to pull all the contact names and numbers into a text box to see that the data I'm receivng is as expected.
From there you may be able to see where it is going wrong.

Regards,
Randomcoder.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
On second thoughts, try this...

B4X:
Sub ListContacts_SelectionChanged (Index, Value)
ListNumbers.Clear
Contact.Value = PimCol.GetItem([COLOR="Red"]Value[/COLOR])
ListNumbers.Add (ListContacts.SelectedIndex & "/" & Contact.LastName & "/" & Contact.MobileTelephoneNumber)
ListNumbers.Refresh 
End Sub

In place of your ListBox 2 code.

Regards,
RandomCoder
 

Oran

Member
Licensed User
RandomCoder....

ARGH.... no dice dude. Tried everything I can think of. I'm about to scrap the project. I've tried just about everyting I know....

Need 2 lists boxes... one for listing contacts, once listed, then click the entry and display the mobile number in the other... sounds really simple but amazingly enough, I can write a space shuttle launch program before I can manage the PIM's....

Dave ///
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Programmers don't quit so easily :sign0156:

The outlook library is one that I've only just started to show an interest in as I want to be able to catch and store messages from certain numbers.
Keep persevering, so far you've found several ways that it can't be done but sooner or later you discover one of the many ways that it can be done.

I'll have a little go at doing this myself and post here soon ;)

Regards,
RandomCoder.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
My Attempt

@ Dave,

I don't like to see anyone struggling when I can be of help, so here is my attempt at what you need.
It only works on the Device as Outlook is really only intended for the device.

Hope that you can now tailor it to your own requirements ;)


PS. I've attached all the files you need including .dll's which we tend not to do as you already have them. I just wanted to make sure that you were able to understand how it all worked.

Regards,
RandomCoder
 

Attachments

  • PIM-Contacts.zip
    13.9 KB · Views: 165

Oran

Member
Licensed User
RC -

Well, I just want to go on the record for saying that you are awesome! That works great. I can see where I need to take it from here for my project. Your assistance is highly appreciated. I consider myself to be the same. I can't stand to see people struggle with something -- provided I can see that he or she has made an attempt to do it on their own. You are the definition of what these forums are all about.

You took the time to help out a noob (forum and this app wise) and spend the time to put me on the path that I need to be on.

KUDOS TO YOU!

Kind Regards,

Dave ///
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Thanks, but comments like that will surely make me big headed :sign0137:

Once I attempted the problem for myself I saw where the difficulty was.
Because you were stripping out the contacts that hadn't got a number, this meant that the Items in the ListBox containing the names was no-longer concurrent with the PIM Items.
You could also try using FindItem to locate the last name of the contact etc. But as this requires some string manipulation and relies on contacts having a unique last name (not always the case when you look at Aunts, Uncles and Cousins etc), which is why I deemed an ArrayList to be a much more simple solution.
Also note that you only need to initialise the objects once, and if required you can dispose of them when you've finished with them.

Regards,
RandomCoder
 
Top