Problem with Contacts

Discussion in 'Questions (Windows Mobile)' started by willisgt, May 13, 2008.

  1. willisgt

    willisgt Active Member Licensed User

    This bit of code crashes for some strange reason:

    Code:
    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:

    Code:
    website   = contact.WebPage
    (I'm sure because if I comment it out, it works.)

    Any ideas?


    Gary

    :sign0085:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What does the error message say?
     
  3. willisgt

    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:
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Try to add check for null values:
    Code:
    If Not (IsNull(contact.WebPage)) Then website = contact.WebPage else website = ""
     
  5. willisgt

    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
     
  6. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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
     
  7. willisgt

    willisgt Active Member Licensed User

    Aha! That did the trick!

    Thanks!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice