Problem with Contacts

willisgt

Active Member
Licensed User
This bit of code crashes for some strange reason:

B4X:
   Contact.New1
   ContactsCollection.New1( "Contacts" )

   ContactsCollection.SortItems( "LastName", false )

   For i = 0 To ContactsCollection.Count - 1

      Contact.Value = ContactsCollection.GetItem(i)
      
      ListBox1.Add( Contact.FirstName & " " & Contact.LastName )


      website   = contact.WebPage

                          msgbox( website )

   Next


The problem is on the line:

B4X:
      website   = contact.WebPage

(I'm sure because if I comment it out, it works.)

Any ideas?


Gary

:sign0085:
 

willisgt

Active Member
Licensed User
I must be losing my mind - i should have included this in the original post.

The error message says:
'An error occurred on sub (sub name)

NullReferenceException

Continue? (y/n)'


Gary

:sign0161:
 

willisgt

Active Member
Licensed User
Problem persists

I made the change you suggested, but the problem persists.

The Outlook.dll version is 1.0.2900.27127.
The OutlookDesktop.dll version is 1.0.2900.27246.

The entire program is attached.


Gary
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes, IsNull will not help here.
Contact.WebPage will only work properly if the contact's webpage field is a valid URL.
The "http://" prefix is also required.
This is a limitation of the underlying .Net CF method.
The only workaround I can think of is to catch this error:
B4X:
        spouse                = contact.Spouse
        suffix                = contact.Suffix
        title                = contact.Title
        website                = GetWebsite
        table1.AddRow(... )
    Next
End Sub

Sub GetWebsite
    ErrorLabel(errGetWebsite)
    Return contact.WebPage
errGetWebsite:
    Return ""
End Sub
 

willisgt

Active Member
Licensed User
Aha! That did the trick!

Thanks!
 
Top