Error

rosshodges

Freshman
Joined
Nov 23, 2002
Messages
28
Visual Basic:
Private Sub ResetNumber()
    If NumericUpDown1.Value = 23 And NumericUpDown2.Value = 59 And NumericUpDown3.Value = 58 Then
        NumericUpDown1.Value = 0
        NumericUpDown2.Value = 0
        NumericUpDown3.Value = 0
    End If
End Sub

i was getting an error when puting my count down timer to 23:59:59 so i made this code but it doesnt work any ideas?

Ross
 
Last edited by a moderator:
Calling

I have have this code

Visual Basic:
Private Sub NumericUpDown2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown2.ValueChanged
        Mydisplay()
        ResetNumber()
        If NumericUpDown2.Value > 59 Then
            NumericUpDown3.Value += 1
            NumericUpDown2.Value = 0

'That as you can see makes the next NumericUpDown go up by
'one(its a count down timer HH:mm:ss but when it gets put up to
'23:59:59 It doesnt no what to do and gives me an error. So i
'tried this

 Private Sub ResetNumber()
        If NumericUpDown1.Value = 23 And NumericUpDown2.Value = 59 And NumericUpDown3.Value = 59 Then
            NumericUpDown1.Value = 0
            NumericUpDown2.Value = 0
            NumericUpDown3.Value = 0


But it totally un does what I have done before!
 
Last edited by a moderator:
the problem is that the ValueChanged event is calling ResetNumber(), then when this function changes the value of the numberUpDown the ValueChanged event is triggeres again, you probably get stuck in an endless loop.

try using a different event than the ValueChanged
 
Any ideas what i can change it to? Or the only thing i am trying to do is stop the error appearing when it reaches the limit of 23:59:59 can you think of a way without using Resetnumber()?
Regards,
Ross
 
Resetnumber is fine, just not where it's being called from.

If you're using a timer, call it from the Timer_Tick event
 
Any ideas what i can change it to? Or the only thing i am trying to do is stop the error appearing when it reaches the limit of 23:59:59 can you think of a way without using Resetnumber()?
Regards,
Ross
 
I agree with Robby, by just changing the location of where the function is called from will fix it.

Resetnumber is fine, just not where it's being called from.

If you're using a timer, call it from the Timer_Tick event

If you absolutely are intent are leaving it similar to what you have, you could set up some flags that once it runs through the first time, the Resetnumber won't be called again until a later time.
 
Back
Top