Re: Cos coming up with NaN
NaN means "Not a Number"
The first thing that leaps out from your code is you are doing mathematical operations on textboxes.
You should convert 2nd.text, 3rd.text into numbers - either singles, doubles or integers depending on what you expect.
Re: Cos coming up with NaN
So do i do that by going for example Dim 1st as Double = 1st.Text?
Re: Cos coming up with NaN
Yes, although you can't have a variable name starting with a number.
Re: Cos coming up with NaN
Okay thanks mate.
Another problem
I went: Dim First as Double = 1st.Text
And it came up saying some error about NullReferenceException was unhandeled. Then it said use New?
Re: Cos coming up with NaN
I'm confused as to how you can have a textbox named "1st"
This is just a variable like any other, and so should be subject to the same naming rules.
Re: Cos coming up with NaN
Sorry dude, i dunno why i typed the abbreviations did it quick. I retyped out the code shoulda just copy and pasted. Yeah they are all first and second and third, but there is still a problem with the way that above is working. NullUnhandledException for
Dim First as Double = First.Text
Re: Cos coming up with NaN
Actually sorry my mind is not working - haven't read your code properly, you need to parse the text value properly :
Code:
Dim First As Double
If Double.TryParse(First.Text, First) Then
'OK
Else
'can't convert
End If
And you need to put code in the If...Else to handle what happens if the content of the text box can't be converted.
Re: Cos coming up with NaN
I just whipped it in and gave it a go, still NaN.
Re: Cos coming up with NaN
OK, so have you checked that all First, Second and Third contain valid numbers within the range that you are expecting?
For Acos to work, you need to pass in a value between -1 and +1 - so what does BeforeInverse evaluate to?
Re: Cos coming up with NaN
To expand on what Paul is saying, I'd create at least 3 intermediate variables, and variables of the correct data type for each text box.
Convert each text box to a number.
Store the calculated numerator in a variable.
Store the calculated denominator in a variable.
Perform the 'BeforeInverse' calculation.
Convert the BeforeInverse variable to another variable (BeforeInverse / Math * Pi).
Put that variable into your Inverse Cosine (which, as already stated, must be between +/-1).
Then, debug by stepping through: you will find your error within seconds.
Re: Cos coming up with NaN