Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NumericUpDown and Timer_Interval 2

Status
Not open for further replies.

DimMeAsNewbie

Technical User
Mar 17, 2007
20
GB
Hey Guys!

I've got a clock that i've done in vb.net 2005. I'm stuck where i need to use NumericUpDown control for users to speed or slow down the tick event.
I've got a vague idea of associating it with the timer but i'm not sure what i really have to do.

Please feel free to contact if you need clarification, maybe i've not put the question in a way everyone can uderstand.

Thanking you in advance!
 
You could use the Tick event to check the NumericUpDown, if the user has changed it then change the Timers Interval...
 
Thanks cjelec for your help, but may main problem is the hard coding in the timer1_tick.
Do i have to do like an if statement like below:

If Me.NumericUpDown1.Increment = 1 Then
timerInterval = 2000

I know this might be completely wrong but hey i'm a newbie still trying to find my way.

Thank you
 
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Me.Timer1.Interval = Cint(NumericUpDown1.Value * 1000)
End Sub


NOTES:
1. Have the minimum value of the NumericUpDown1 set to One (1).
2. The Timer's interval is set to milliseconds... and that's why the * 1000 (make it every 1sec). Of cource, the interval may not be of 1sec multiple, because the NumericUpDown1's Increment may not be integer.

I dont know if i am clear
 
Thanks TipGiver , i seem to be going somewhere The code below is what i've done as you suggested, but i think i've declared timer1.interval wrong because it's highlighted. If i don't dim it, it's showing a message that "timer is not a member of the windows1, Form1".
Do i need to code anything in the timer1_tick?

code:

Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
Dim Timer1.Interval As Interger
Me.Timer1.Interval = CInt(NumericUpDown1.Value * 1000)
End Sub
 
You need to drag/drop a Timer to the form (found in components toolbox), the default given name is Timer1.

Declaring it in the NumericUpDown_ValueChanged, would make it disappear as soon as the Sub has finished running.

After you have drag/dropped the Timer, double click its icon at the bottom of the screen, this will give you the Sub that fires when the Timer ticks.

Then use TipGivers example to set the timer when you change the NumericUpDown.
To test your app, type Beep() in the Sub Timer1_Tick event, and drive your self insane :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top