Problems with slider

Hello Community,

I have a problme with sliders. Please have a look at the picture.


I use the slider to switch between values from 0 to 180. Default is 90. In addition I have the plus/minus buttons to decrease the slider value by a specific value - default is 5.

When I trigger the plus button the value for the slider becomes 94 instead of 95. this is because the slider seams to caluclate the value new innternally.

At this point all is find (event "for any button")

But when I set value via "Set SliderHead.ThumbPosition" the event "Slider.PositionChanged" is triggered. That is what I expect but there must be an internal wrong calculation. This point of blocks gives me not the expected value 95 but 93.6 (which leads to 94 rounded).

image

How can I solve this problem?

the slider does have only 100 different values...

180/100 = 1.8, so your step is 1.8
and
52 x 1,8 = 93.6

Taifun

1 Like

First of all: thank you very much for the quickest answer ever and in fact the explanation for the behavior.

Where can I find such detailed information to the components to avoid such tripping hazards in future?

That what you wrote sounds absolutly plausible to me but I did not expect it because: when I move the slider directly and display the thumb position e.g. in a label on-the-fly there are sometimes values like: 96.635376.

So what can I do now: maybe I have to calculate the value manually in a way that I reache the disired value. But when I think about it it seams to me that the granularity I want never can be reached due to the fact that the slider only can store 100 values. Is this right?

a search in the community often helps...
see here Search results for 'slider 100' - MIT App Inventor Community
also for some ideas to overcome this

Taifun

Yes you are right. Thank you. I will have a deeper look at this. I searched for slider problems but did not find that what you suggested. Sorry.

So... I was shortly convinced to throw out the sliders and use only the buttons (in combination with long press and a clock to quickly change the values) but now I found another solution. I will keep it in that way. I can use the slider to overcome large value ranges and use the button for detail. I testet it and it seams to be working. Every few values I have to click e.g. the plus button 2 times to overcome a value by 1 point. But it does not matter.

Essential is that I send the value I see in the label to Arduino because I use this for servo calibration and other purposes. But that is given because for sending I changed the logic to: use the shown value from label and not the value from ThumbPosition (rounded or not).

Thanks again!

1 Like

you are welcome
I moved the solution marker to another post...
the post you selected is not really a solution...

Taifun

As you like. For me it was the solution because it was the explanation for the slider behavior :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.