473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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
4 1333
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: strout | last post by:
function F(e) { return function(){P(e)} } Can anybody tell me what the code is doing? If return another function all in a function I would do function F(e)
10
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
5
by: Dmitriy Lapshin [C# / .NET MVP] | last post by:
Hi all, I think the VB .NET compiler should at least issue a warning when a function does not return value. C# and C++ compilers treat this situation as an error and I believe this is the right...
12
by: Michael Maes | last post by:
Hello, I have a BaseClass and many Classes which all inherit (directly) from the BaseClass. One of the functions in the BaseClass is to (de)serialize the (inherited) Class to/from disk. ...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
2
by: mosesdinakaran | last post by:
Hi everybody, Today I faced a problem where I am very confused and I could not solve it and I am posting here.... My question is Is is possible to return a value to a particular function ...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.