Return value in function

S

shapper

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
 
M

Mark Rae

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
 
A

Abraham Andres Luna

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

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

Gozirra

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.


I did as follows:

Dim obj As New MyClass.Obj
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top