We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Does Slider Work ?
#1
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
Reply
#2
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.
ZS
Reply
#3
Thumbs Up 
Thank you ZS
Reply
#4
What is error
ZS
Reply
#5
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
Reply
#6
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.
[-] The following 2 users Like litdev's post:
  • ata, z-s
Reply
#7
Thank you Litdev
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)