Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how check if an object is set to an instance

Posted on 2004-09-24
3
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

660 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