Page 1 of 1

Calculation errors

Posted: Wed Sep 24, 2008 1:17 am
by Alistair
I am running into calculation errors that seem to be coming from Revolution.

I am reading the settings of three scrollbars using statements of the form:

put the thumbposition of scrollbar "Efield" into Efield

When I display Efield the value is correct. If I move one or more of the scrollbars and then bring them back to their original positions, the values of the variables are always correct but the result of the calculation changes. How can this occur.

Also, if a set a scrollbar to range from 0 to 100 I find that it is not possible to set the scrollbar to either 50 or 150.

Posted: Wed Sep 24, 2008 1:21 am
by Mark
post your script

Posted: Wed Sep 24, 2008 1:27 am
by Alistair
Here is the part of the script where the problem is occurring

I am using the second PUT statement to watch the values of the variables and the result of part of the calculation



put the thumbposition of scrollbar "mIz" into mIz
put the thumbposition of scrollbar "Efield" into Efield
put the thumbposition of scrollbar "Bfield" into Bfield
if bfield <> 0 then
put scaleFac*sqrt(2*mIz*Efield/(Bfield*Bfield)) into r1
put mIz, Efield, Bfield, 2*mIz*Efield/(Bfield*Bfield)
end if

Posted: Wed Sep 24, 2008 2:05 am
by Mark
Hi Alistair,

I guess that the value of scaleFac changes. Is it posible that the startValue and endValue of the scrollbars change?

Best,

Mark

Posted: Wed Sep 24, 2008 2:24 am
by Alistair
Hi Mark

No the startValues and endValues and the scalefactor don't change. When I display the values of the variables they are correct. It seems to be the calculation itself that is producing a varying result.

Posted: Wed Sep 24, 2008 2:36 am
by Mark
Hi Alistair,

What are the values and what are the results?

Mark

Posted: Wed Sep 24, 2008 2:50 am
by Alistair
Hi Mark

As an example, if Miz is set to 100 and EField is set to 1, then repeatedly setting Bfield to 2 (setting the slider to another value, then setting it to 2) produces the following results: 2.636, 2.670, 2.705, 2.740. The correct value is 2.72.

Posted: Wed Sep 24, 2008 8:15 am
by Klaus
Hi Alistair,

I also experienced some strangeness with scrollbars in the past, they were returning fractions althougg I did not set the numberformat of anything else.

The range was from -4 to 4.

So I ended with somthing like:

Code: Select all

...
put ROUND(the thumbpos of sb "whatever scrollbar") into sb_value
...
And my calculations were correct and happy ever after :-)

Hope that helps.


Best from germany

Klaus

Posted: Wed Sep 24, 2008 8:45 am
by Alistair
Hi Klaus

Adding Round did solve the problem for integer values but the problem is that the range is meant to go from 0 and therefore fractional values such as 0.3 and intermediate values,say, between 1 and 2 are valid.

Posted: Wed Sep 24, 2008 9:12 am
by Klaus
Hi Alistair,

you can define the number of fractions that ROUND should return with a second parameter to that function, see the docs for ROUND:

put round(100/3,1) -> 33.3
put round(100/3,2) -> 33.33
etc...


Best

Klaus

Posted: Thu Sep 25, 2008 8:58 am
by Alistair
Hi Klaus,

Thanks for that suggestion. That fixed the problem. I should have thought to check the Dictionary when you first suggested using the Round function.

Thanks again

Alistair

Posted: Thu Sep 25, 2008 9:16 am
by Mark
Hi Alistair,

One more idea: add the following brief script to your slider object and make sure to set the showValue of the slider to false or set the pageInc to 0, to hide the tics (you'll need to experiment with what works best for you).

Code: Select all

on mouseUp
   set the thumbPos of me to round(the thumbPos of me)
end mouseUp
If you use this script while the tics of the slider are visible, you will see that the tics are purely cosmetic and also confusing.

Best,

Mark

Posted: Fri Sep 26, 2008 5:11 am
by Alistair
Hi Mark

Thanks for that suggestion. I am using the slider to set a value so in this case displaying the value is important.

Regards

Alistair

Posted: Fri Sep 26, 2008 8:31 am
by Mark
Alistair, just to make sure that I'm clear, you can display the value without displaying the tics.

Mark

Posted: Fri Sep 26, 2008 9:34 am
by Alistair
Yes, thanks, Mark. I'm displaying the value but not the tics.

Alistair