System.NullReferenceException was unhandled

This particular error has been a real thorn in my side in different sreas of this program, but we'll just deal with this instance of it.  The code line that tripped the error is  "newstr = NumToWord(Int(numstr / 10 ^ 2))"

And the error is       --         System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
 .



   I did try inserting the key word NEW between As   and  String in the Declaration statement. But, got another error with that.




Private Sub NTW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NTW.Click

        Dim numstr As String
        Dim newstr As String
        Dim NumToWord As String
        Dim tempstr As String = ""


        numstr = TextBox9.Text
        If numstr = "0.00" Then
            newstr = "Zero"
            TextBox10.Text = NumToWord

 If numstr >= 10 ^ 2 Then

            newstr = NumToWord(Int(numstr / 10 ^ 2))
            numstr = ((numstr / 10 ^ 2) - Int(numstr / 10 ^ 2)) * 10 ^ 2

        ElseIf numstr = 0 Then
            tempstr = tempstr & newstr & "hundred "

        Else

            tempstr = tempstr & newstr & "hundred "

        End If
jampostGeneral MaanagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Neil RussellTechnical Development LeadCommented:
newstr = NumToWord(Int(numstr / 10 ^ 2))


You are taking the INT of a STRING devided by 10 ^2
numstr /10^2

Maybe? Its late and im tired :P
0
jampostGeneral MaanagerAuthor Commented:
    Neilsr,

         Yes, That's exactly what the code is trying to do.  You're doing well in the PM.  I think Itellesence does not miss anything.  It's a blessing and a pain all wrapped up in one.
0
ThomasianCommented:
I assume that you have a function named "NumToWord" since you are passing a parameter to it.

The problem is you also have a local variable named NumToWord. Rename the local variable to something else to fix this.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

jampostGeneral MaanagerAuthor Commented:
This was written as a function, but I am testing it inside of a click event named NTW.  
0
ThomasianCommented:
What is the use of the variable "NumToWord". Note that you never set the value for it which is causing the error.
0
jampostGeneral MaanagerAuthor Commented:
       I got this code from another expert on Experts Exchange, so I'm just feeling my way around the code. I picked up on the same thing you have. It's like NumToWord is a fifth wheel.
        Isn't the keyword New suppose to fix problems like this? The variable is being used before a value is set. I know I am going to have to trim up this code, but I am just curiouse about this error.
0
ThomasianCommented:
The variable is being used before a value is set. I know I am going to have to trim up this code, but I am just curiouse about this error.

That is exactly the cause of the error. The variable was not set before it was used.

Can you explain what you are trying to do?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Can you post the full definition of NTW_Click? You've got multiple if blocks and only one is visibly ended, so it's difficult to tell how the code is structured.
0
jampostGeneral MaanagerAuthor Commented:
I think this code has problems and I will work them out. I have the same error message on the variable "newstr", and newstr is an output variable. This is pretty complex code. I am going to work on it and bring it back another time. Thank you for your help.  
0
käµfm³d 👽Commented:
How is "newstr" an "output" variable? You are working in a Sub--there is no return value, and the parameters are dictated by the delegate signature.

If you give the overall goal, I'm sure one or more of us can help you reach it  = )
0
jampostGeneral MaanagerAuthor Commented:
Thank you and happy New Year
0
jampostGeneral MaanagerAuthor Commented:
Kaufmed,

     I have absolutly no doubt that you are capable of assisting me on this. You helped me a few times before.  This procedure was offered to me by an expert on this site. I think it has potential, but it has a lot of issues. Some of whitch you pointed out. I have decided to work on it and post my problems one at a time. I posted a new one just a couple of minutes ago.   Thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.