467,878 Members | 1,263 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,878 developers. It's quick & easy.

Return value in function

Hello,

I have a function inside a compiled class which code is as follows:
Public Function Send() As Boolean

' [Some code]

Try

' [Some code]

Return True

Catch ex As Exception

' [Some code]

Return False

End Try

End Function
In my aspx.vb code I have:

Dim obj As New MyNamespace.MyClass

If obj.Send Then

Else

End If

I am getting an error on code line "If obj.Send Then":

System.NullReferenceException: Object reference not set to an instance
of an object.

I have no idea what is going on. Shouldn't my class function return
true or false?

Thanks,

Miguel

Oct 11 '06 #1
  • viewed: 1113
Share:
4 Replies
"shapper" <md*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I am getting an error on code line "If obj.Send Then":

System.NullReferenceException: Object reference not set to an instance
of an object.
That means you're not referencing your class correctly.
I have no idea what is going on.
Indeed.
Shouldn't my class function return true or false?
It might if you include some decent exception handling... Do a Google for
Try Catch Finally
Oct 11 '06 #2
actually, you have to set that send() function as a static method if you
plan to just call it without instantiating the MyClass class
hope that helps

"shapper" <md*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
| Hello,
|
| I have a function inside a compiled class which code is as follows:
|
|
| Public Function Send() As Boolean
|
| ' [Some code]
|
| Try
|
| ' [Some code]
|
| Return True
|
| Catch ex As Exception
|
| ' [Some code]
|
| Return False
|
| End Try
|
| End Function
|
|
| In my aspx.vb code I have:
|
| Dim obj As New MyNamespace.MyClass
|
| If obj.Send Then
|
| Else
|
| End If
|
| I am getting an error on code line "If obj.Send Then":
|
| System.NullReferenceException: Object reference not set to an instance
| of an object.
|
| I have no idea what is going on. Shouldn't my class function return
| true or false?
|
| Thanks,
|
| Miguel
|
Oct 11 '06 #3
I did as follows:

Dim obj As New MyClass.Obj

Abraham Andres Luna wrote:
actually, you have to set that send() function as a static method if you
plan to just call it without instantiating the MyClass class
hope that helps

"shapper" <md*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
| Hello,
|
| I have a function inside a compiled class which code is as follows:
|
|
| Public Function Send() As Boolean
|
| ' [Some code]
|
| Try
|
| ' [Some code]
|
| Return True
|
| Catch ex As Exception
|
| ' [Some code]
|
| Return False
|
| End Try
|
| End Function
|
|
| In my aspx.vb code I have:
|
| Dim obj As New MyNamespace.MyClass
|
| If obj.Send Then
|
| Else
|
| End If
|
| I am getting an error on code line "If obj.Send Then":
|
| System.NullReferenceException: Object reference not set to an instance
| of an object.
|
| I have no idea what is going on. Shouldn't my class function return
| true or false?
|
| Thanks,
|
| Miguel
|
Oct 11 '06 #4
Since you have created an instance of your object then the error has to
be happening in the [Some Code] you have before your try/catch block of
the send method. It is also possible that the error is occuring in the
some code located in your catch statements.

Without code can't really tell. You should be able to simply step
through the code and see on what line it blows. Then you will know
which object is null.

shapper wrote:
I did as follows:

Dim obj As New MyClass.Obj

Abraham Andres Luna wrote:
actually, you have to set that send() function as a static method if you
plan to just call it without instantiating the MyClass class
hope that helps

"shapper" <md*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
| Hello,
|
| I have a function inside a compiled class which code is as follows:
|
|
| Public Function Send() As Boolean
|
| ' [Some code]
|
| Try
|
| ' [Some code]
|
| Return True
|
| Catch ex As Exception
|
| ' [Some code]
|
| Return False
|
| End Try
|
| End Function
|
|
| In my aspx.vb code I have:
|
| Dim obj As New MyNamespace.MyClass
|
| If obj.Send Then
|
| Else
|
| End If
|
| I am getting an error on code line "If obj.Send Then":
|
| System.NullReferenceException: Object reference not set to an instance
| of an object.
|
| I have no idea what is going on. Shouldn't my class function return
| true or false?
|
| Thanks,
|
| Miguel
|
Oct 11 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by strout | last post: by
10 posts views Thread by LaEisem | last post: by
3 posts views Thread by tshad | last post: by
5 posts views Thread by Dmitriy Lapshin [C# / .NET MVP] | last post: by
12 posts views Thread by Michael Maes | last post: by
20 posts views Thread by lovecreatesbeauty | last post: by
2 posts views Thread by mosesdinakaran | last post: by
7 posts views Thread by Terry Olsen | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.