Slider Issue

My app uses a Timer. I adjust its speed by selecting values from a Popup Menu, but I’d like to use a Slider instead. This is my code:

Slider1.MinimumValue = 5
Slider1.MaximumValue = 100

Timer1.Period = Slider1.Value

I have the code in a ValueChanged Event Handler. It seems to me this should work but it doesn’t. Even at a MinimumValue of 5, the Timer moves way too fast. Any help would be greatly appreciated.

Thanks!

Well, a Timer works in milliseconds and the lower the value, the shorter the time frame.

If you’re trying to set the timer to 5 seconds, then either adjust the slider’s value to a higher increment or apply some math like so:

Timer1.Period = Slider1.Value * 1000
2 Likes

Ah… So the lower the value, the faster it goes. Anyways, your suggestion works great.

Thanks so much!

1 Like

The lower the timer value, the oftener it fires. :wink:

Yes, I found that out as well. To make it fire more evenly, you can put this in the ValueChanged Event:

Var maxValue As Integer = Slider2.MaximumValue
Var sliderValue As Integer = maxValue - Slider2.Value
Var minPeriod As Double = 200  // Fastest speed (200 ms per word = 300 WPM)
Var maxPeriod As Double = 2000 // Slowest speed (2000 ms per word = 30 WPM)
Var factor As Double = Exp(Log(sliderValue / maxValue) * 2)
Var period As Double = minPeriod * (1 - factor) + maxPeriod * factor
Var wordsPerMinute As Integer = 60000 / period
Timer1.Period = period