Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how check if an object is set to an instance

Posted on 2004-09-24
3
Medium Priority
?
237 Views
Last Modified: 2010-04-23
hello

i keep getting object not set to an instance

when i check if an object (MyObject.OrganisationDetails.ContactDetails.Telephones(0)) exists:

i tried:
            If Not IsDBNull(MyObject.OrganisationDetails.ContactDetails.Telephones(0)) Then
            If Not (MyObject.OrganisationDetails.ContactDetails.Telephones(0)) is nothing Then

but both return that same error.

how do i check an object that may not exist - to see if it does exist






0
Comment
Question by:MrKevorkian
3 Comments
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 1000 total points
ID: 12143660
Do you mean like this?

Dim bExists As Boolean = False

If Not MyObject Is Nothing Then
    If Not MyObject.OrganisationDetails Is Nothing Then
        If Not MyObject.OrganisationDetails.ContactDetails Is Nothing Then
            If Not MyObject.OrganisationDetails.ContactDetails.Telephones(0) Is Nothing Then
                bExists = True
            End If
        End If
    End If
End If

If bExists Then...
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 12144940
perfect.

0
 
LVL 6

Expert Comment

by:KGreg
ID: 12144955

public function HasTelephoneNumber as boolean
        Try
             if MyObject.OrganisationDetails.ContactDetails.Telephones.Count > 0 then
                 Return True
             end if
        Catch ex As NullReferenceException
             return False
        End Try
end function


KGreg
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question