On 13-Apr-07, at 9:26 PM, Maury McCown wrote:

> I am TOTALLY stumped about why this code won't work, and it's killing
> me. Can someone PLEASE look into this and show where I'm screwing up?
> Here's the setup:
>
> 1. A window with 2 ListBoxes (ListBox1 and ListBox2).
> 2. Both ListBoxes should have 2 columns (you can make just column 0
> visible in ListBox1).
>
> In ListBox1's Open event, enter the following code:
>
> ////////////
> me.addRow "All"
>
> dim groups() as AddressBookGroup
> dim group as AddressBookGroup
>
> groups = System.AddressBook.Groups
>
> for each group in groups
>    if ubound(group.Groups) >= 0 then
>      me.AddFolder group.name
>    else
>      me.addRow group.name
>    end if
>
>    me.cell(me.LastIndex,1) = group.UniqueID
> next
>
> me.listIndex = 0
> ////////////
>
>
> In ListBox1's Change event, enter the follwoing:
>
> ////////////
> Dim data, datas() as AddressBookData
> Dim group, groups() as AddressBookGroup
> Dim contact, contacts() as AddressBookContact
> Dim i, c as Integer
>
> ListBox2.DeleteAllRows
>
> if me.ListIndex > 0 Then
>    groups = System.AddressBook.Groups
>
>    for Each group in groups
>      if group.UniqueID = me.Cell(me.ListIndex,1) Then
>        Exit
>      end
>    next
>
>    contacts = group.contacts
>    For i = 0 to Ubound(Contacts)
>      if contacts(i).FirstName = "" then
>        ListBox2.AddRow contacts(i).EmailAddresses
>      else
>        ListBox2.addrow contacts(i).FirstName + " " + contacts
> (i).LastName
>      end
>      ListBox2.cell(i,1) = contacts(i).EmailAddresses
>    Next
>
> Elseif me.ListIndex = 0 Then
>
>    Contacts = System.AddressBook.Contacts
>
>    for each contact in contacts
>      if me.cell(me.listindex,1) = contact.UniqueID then
>        exit
>      end if
>    next
>
>    data = contact.EmailAddresses
>
>    if data <> nil Then
>      for each Contact in contacts
>        ListBox2.AddRow contact.FirstName + " " + contact.LastName
>        ListBox2.Cell(ListBox2.LastIndex,1) = data.Value
>      next
>    End
>
> End
> ////////////
>
>
> When you run the project, everything will look *wonderful* except
> that when you click the "All" address group, each contact's
> associated email isn't being displayed.
>
> What am I doing wrong? I'M DYING TRYNG TO FIGURE THIS OUT!
>
>
>
> Later,
> Maury

A few glitches

data = contact.EmailAddresses can be an array so you have to see if  
there is a count > 0 before trying to get a value

Put this in the change

   ////////////
   Dim data  as AddressBookData
   dim datas() as AddressBookData
   Dim group  as AddressBookGroup
   dim groups() as AddressBookGroup
   Dim contact as AddressBookContact
   dim contacts() as AddressBookContact
   Dim i, c as Integer

   ListBox2.DeleteAllRows

   if me.ListIndex > 0 Then
     groups = System.AddressBook.Groups

     for Each group in groups
       if group.UniqueID = me.Cell(me.ListIndex,1) Then
         Exit
       end
     next

     contacts = group.contacts
     For i = 0 to Ubound(Contacts)
       contact = contacts(i)

       ListBox2.AddRow ""
       if contact.FirstName = "" then
         ListBox2.cell(ListBox2.LastIndex,0) = contact.EmailAddresses
       else
         ListBox2.cell(ListBox2.LastIndex,0) = contact.FirstName + "  
" + contact.LastName
       end
       If contact.EmailAddresses.Count > 0 then
         ListBox2.cell(ListBox2.LastIndex,1) =  
contact.EmailAddresses.Value
       end if
     Next

   Elseif me.ListIndex = 0 Then

     Contacts = System.AddressBook.Contacts

     for each contact in contacts

       ListBox2.AddRow contact.FirstName + " " + contact.LastName

       data = contact.EmailAddresses

       if data <> nil and data.Count > 0 Then

         ListBox2.Cell(ListBox2.LastIndex,1) = data.Value

       end if

     next

   End
   ////////////



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to