Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Counting Down in VB6


ghost's Avatar
0 0

how would i make a program that counts down from 1 hour and gos till 0? kinda like a timer for an oven although on your computer.


Mr_Cheese's Avatar
0 1

make a timer and a text box.

then have


text1.text = "600000"   - (or whatever 1 hour is in seconds)

Timer.interval = 1000

------Timer Sub-------

Dim TimeCount as integer

TimeCount = val(text1.text)

TimeCount = TimeCount - 1

text1.text = TimeCount

------End Sub--------

easy :)


ghost's Avatar
0 0

thanks, but i did it another way b4 u replied.


Private AlarmTime As Date

Private Sub Form_Load()
    AlarmTime = DateAdd("h", 1, Now)
End Sub


Private Sub Timer1_Timer()
Dim txt As String

    txt = Format$(AlarmTime - Now, "h:mm:ss")
    Label1.Caption = txt
End Sub


now i also wanted to make it log off the computer when it goes to 0. this counts down from 1:00:00 to 0:00:00.


ghost's Avatar
0 0

Mr_Cheese wrote: make a timer and a text box.

then have


text1.text = "600000"   - (or whatever 1 hour is in seconds)

Timer.interval = 1000

------Timer Sub-------

Dim TimeCount as integer

TimeCount = val(text1.text)

TimeCount = TimeCount - 1

text1.text = TimeCount

------End Sub--------

easy :) i was just wondering…wouldn't this depend more on the speed of your puter rather than actual time?


Mr_Cheese's Avatar
0 1

i surpose, but it does what he asked, and the increased speed is gonna be extremely minimal, compared to how he did it.


ghost's Avatar
0 0

ok i got that, but what about login off windows? do i need API calls or what?


Mr_Cheese's Avatar
0 1
call Shell ("logoff", vbHide)

ghost's Avatar
0 0

how would i put that in the code i already made? i dont really see anything i can loop?


Mr_Cheese's Avatar
0 1

just put it in a If statement, thats in the timer.

so like:

If Time = XXX then Call Shell….

end if