Small Basic Forum

Full Version: How Does Slider Work ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everybody Smile  The following does not work properly.Could you please help me understand the slider logic?

Code:
x[1]= Shapes.AddText(1)
Shapes.Zoom(x[1],7,7)
Shapes.Move(x[1],600,120)
For i= 2 To 12
  x[i]= Shapes.AddText(i)
  Shapes.Zoom(x[i],7,7)
  y= Shapes.GetTop(x[i-1])
  Shapes.Move(x[i],600,y+105)
  y= Shapes.GetTop(x[i])
EndFor

LDControls.SliderMaximum= 2
Slider= LDControls.AddSlider(40,600,"V")
Shapes.Move(slider,500,100)
t= LDControls.SliderGetValue(slider)
Stack.PushValue("t",t)
LDControls.SliderChanged= change

Sub change
  t= Stack.PopValue("t")
  z= LDControls.SliderGetValue(slider) 
    If z>t Or z=t Then
      For i= 1 To 12
        Shapes.Move(x[i],600,Shapes.GetTop(x[i])-2)
      EndFor
      v= LDControls.SliderGetValue(Slider)
      Stack.PushValue("t",v)
    ElseIf z<t then
      For i= 1 To 12
        Shapes.Move(x[i],600,Shapes.GetTop(x[i])+2)
      EndFor
      v= LDControls.SliderGetValue(Slider)
      Stack.PushValue("t",v)
  EndIf
EndSub
I edited your posts and added mycode so it can be easily copied.
For more info visit: https://litdev.uk/mybb/misc.php?action=help&hid=7
I will study your code.
Thank you ZS
What is error
The slider movement is not consistent. The numbers do not always stay where they should be. For example; When I drag the number 1 to the last value of the slider, the y axis should always come to the same place. However, sometimes the number 1 goes too high on the y axis and does not appear when I call it back. thank you
Hi ata,zs,coder

I'm totally not sure I fully follow what you are describing, but I think it may be the following.

The amount you move the images is always + or - 2 pixels, depending on if the slider is high or lower compared to the last time it was set.

The slider event will only be called 'as the OS detects a change'.  If you move it very fast, then the slider may go up 20% and the images move up 2 pixels.  If you then move the slider slowly down 20% to where you started the slider event may be called several (say 5 times) and the images will move a total of 10 pixels down.

So, depending on the speed you move the slider, the images and slider can get out of sync.

To fix, I first suggest that you write out some debugging data like TextWindow.WriteLine(z) inserted after line 21.

Then, what you want is the absolute position (y coord) of the images to be related to the absolute position (value) of the slider - no need to store old values in the stack.  I leave you to figure this a bit, rather than modifying your code.
Thank you Litdev