.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

null reference could result

1 REPLY 1
Reply
Message 1 of 2
Anonymous
299 Views, 1 Reply

null reference could result

I know some people don't like to see questions here that include any com
interop elements, but this is a dotnet question so does not belong in the
vba group.
acad2009 vbnet 2008 express
how to avoid the compiler warning:
Variable 'ArrayObjects' is used before it has been assigned a value. A null
reference exception could result at runtime.

given
Dim ArrayObjects() As AcadEntity

...some code...

Try

ReDim ArrayObjects(0)

ArrayObjects(UBound(ArrayObjects)) = oSideLine

Catch ex As ApplicationException

m_Util.Logentry("error " & ex.Message)

End Try

...more code...then...

Try

If ArrayObjects Is Nothing Then <------------here is the warning location at
"ArrayObjects"

m_Util.Logentry("error ArrayObjects Is Nothing")

Else

SelectionSetWblock.AddItems(ArrayObjects)

End If

Catch ex As ApplicationException

End Try



what should I be doing in such cases (using an array)

i wouldn't think you'd do Dim ArrayObjects() As AcadEntity = Nothing

like you might with a simple object???

thanks

mark
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

A 'dotnet question' will probably get more answers on
the relevant Microsoft newsgroups.

This isn't a quesiton about using the managed .NET API,
it is a basic VB.NET language usage question.

I'm sure someone here that's more familiar with VB.NET
will answer you, but I generally don't answer basic language
usage questions here, because this really isn't the VB.NET
(or C#) language newsgroup, this newsgroup is about using
the managed AutoCAD API.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"mp" wrote in message
news:6368878@discussion.autodesk.com...
I know some people don't like to see questions here that include any com
interop elements, but this is a dotnet question so does not belong in the
vba group.
acad2009 vbnet 2008 express
how to avoid the compiler warning:
Variable 'ArrayObjects' is used before it has been assigned a value. A null
reference exception could result at runtime.

given
Dim ArrayObjects() As AcadEntity

...some code...

Try

ReDim ArrayObjects(0)

ArrayObjects(UBound(ArrayObjects)) = oSideLine

Catch ex As ApplicationException

m_Util.Logentry("error " & ex.Message)

End Try

...more code...then...

Try

If ArrayObjects Is Nothing Then <------------here is the warning location at
"ArrayObjects"

m_Util.Logentry("error ArrayObjects Is Nothing")

Else

SelectionSetWblock.AddItems(ArrayObjects)

End If

Catch ex As ApplicationException

End Try



what should I be doing in such cases (using an array)

i wouldn't think you'd do Dim ArrayObjects() As AcadEntity = Nothing

like you might with a simple object???

thanks

mark

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost