Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


how check if an object is set to an instance

Posted on 2004-09-24
Medium Priority
Last Modified: 2010-04-23

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

Question by:MrKevorkian
LVL 10

Accepted Solution

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

Author Comment

ID: 12144940


Expert Comment

ID: 12144955

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


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

564 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