Simple polynomial produces error ONLY for a certain input, otherwise works
Dear All,
I'm new here, and new to Visual Basic, (but having a background in C and C++).
Sorry if my question is foolish, but I'm really puzzled by the problem I'm facing now.
I'm trying to write a simple user defined function, "calctemp(sensor, resistance As Double) As Double" below, which calculates a polynomial to the 6th degree
It should take the 7 coefficients of this polynomial (K_1 ... K_7) from cells in the same row as input cell "sensor" (with offset +1, +2... +7 to the right from that input cell).
And "resistance" is the variable taken with double precision, as the second input.
I wrote the code below. And it worked nicely, with the desired precision.
But, if I input resistance = 2774.0
it gives #VALUE! error. Regardless from the polynomial coefficients! Regardless from anything else, seemingly, except for the power of the polynomial.
This error occurs at power 5, and present above.
I don't know what's so special about this number 2774.0, already 2774.000001 gives a numerically correct result. Other round numbers (3300.0, whatever) work too, and I did not find other input values failing so far.
Am I doing something incorrect in the code? I'm not sure my usage of "sensor.Offset(0, 1).Value" is the recommended way to select cell values next to the input cell (in principle, I would think the input "sensor" would need a type, like "As Address", to be sure we are referring to the cell address, and shifting that with the .Offset(,) method) But again, this part seems to work...
I would be glad for any debugging ideas!
I'm using Excel for Mac 2011.
PHP Code:
Function calctemp(sensor, resistance As Double) As Double
Dim res As Double
Dim K_1 As Double, K_2 As Double, K_3 As Double, K_4 As Double
Dim K_5 As Double, K_6 As Double, K_7 As Double
Bookmarks