0

well, ive been using VB6 for a year now, but i cant get this to work

i have 3 txt boxs, and a cmd button, and a timer thingy(dont know how to use timer yet :P )

it needs to count down in seconds, min and hours.

this is the code i have done so far, but it doesnt work properly, could someone help me debug it please.

Private Sub Timer1_Timer()

If sectxt.Caption > 0 Then
    sectxt.Caption -1
ElseIf sectxt.Caption >= 59 Then
    sectxt.Caption = 59
End If

If sectxt.Caption = 0 Then
    mintxt.Caption -1
    Csectxt.Caption = 59
    If mintxt.Caption = 0 Then
        hourtxt.Caption -1
        mintxt.Caption = 59
    End If
End If

If mintxt.Caption <= 0 Then
    mintxt.Caption = 0
End If

If houttxt.Caption <= 0 Then
    houttxt.Caption = 0
End If

End Sub

Private Sub startcmd_Click()
If startcmd.Caption = "Start Washing" Then
Timer1.Enabled = True
startcmd.Caption = "Pause / Stop"
End If

End Sub
3
Contributors
8
Replies
10
Views
11 Years
Discussion Span
Last Post by Slavrix
0

Hi, Slavrix, and welcome.
You didn't say in what way it wasn't working, what error message(s) do you get?
You could do it something like this, with nested If...Else statements, I assumed you would have first put something in the textboxes. Basically, every time the Sec or Min textboxes change from 0 to 59 you would have to check the other boxes and update them

Private Sub Timer1_Timer()

If txtSec.Text > 0 Then
    txtSec.Text = txtSec.Text - 1
Else                                'if zero
    txtSec.Text = 59

        If txtMin.Text > 0 Then     'update mins
            txtMin.Text = txtMin.Text - 1
        Else
            'check if Hour is 0, and if it is, then stop timer, else continue
            txtMin.Text = 59
        End If
        
End If
End Sub
0

oooo, man

thx alot. it works awsomely. i love it.

THX THX THX THX THX :lol: :lol: :cool: :cool:

0

ummm, when i go to run it, when the hour box is zero, the counter still resets the minutes to 59.

how can i fix that?

0

dont worry i think i got it

something like

If txtSec.text = 0
   txtMin.text = 0
   txtHour.text = 0 then

   Timer1.enabled=false
end if

could someone tell me if this is correct or not pls

0

when the hour box is zero, the counter still resets the minutes to 59.
QUOTE]

When the hour box changes from 1 to 0, there are still 59mins 59 secs left to go. But maybe you mean right at the end?

If txtSec.Text = 0 And txtMin.Text = 0 And txtHour.Text = 0 Then
      Timer1.Enabled = False
End if
0

here is my count down code

Private Sub cmd_Click()
    Timer1.Enabled = Not Timer1.Enabled
    cmd.Caption = IIf(Timer1.Enabled, "Pause", "Start")
End Sub

Private Sub Form_Load()
    Timer1.Interval = 1000
    Timer1.Enabled = False
    cmd.Caption = "Start"
    txtmin.Text = 0: txtsec.Text = 0: txthour.Text = 1
End Sub

Private Sub Timer1_Timer()
    If txtsec.Text > 0 Or txtmin.Text > 0 Or txthour.Text > 0 Then
        If txtmin.Text = 0 And txthour.Text > 0 Then _
            txtmin.Text = 60: txthour.Text = txthour.Text - 1
        If txtsec.Text = 0 And txtmin.Text > 0 Then _
            txtsec.Text = 60: txtmin.Text = txtmin.Text - 1
        txtsec.Text = txtsec.Text - 1
    Else
        cmd_Click
    End If
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.