• Log in or sign up for an account here: https://www.sythe.org/login

Timers

Osmosis

Retired Australian Mod

Banned
Joined
Apr 29, 2005
Sythe Gold
0
Messages
2,695
Location
Brisbane, Australia
Yeah so it's been quite some time since I've used VB, and I'm a bit (well a lot) rusty on a few things.

I'm trying to make a program that shutsdown/logsoff your computer after a an amount of time that the user enters.

I can't remember how to get the timer set up so it counts down, and displays the time untill shutdown (hh:mm:ss:), and then when it reaches 00:00:00 shuts down the comp. I can force shutdown/log off using shell, so don't really need a hand in that department.
 
Code:
Shell ("Shutdown -s -t 5")

thats waits 5 seconds before shutting down. (i think it displays the count down im not sure).

But if you must have the 00:00:00 format its pretty simple and just basic maths. i will be doing this free hand so there could be errors but you should be able to fix them up yourself.
I'll try and comment it as best i can (i hate commenting)

Code:
private sub timer1_timer()
  Dim Hrs as long, Mins as long, Secs as long 'deccy's
  hrs = val(split(label1.":")(0)) 'gets hrs remaining from the label
  mins = val(split(label1.":")(1)) 'gets mins remaining from the label
  secs = val(split(label1.":")(2)) 'gets secs remaining from the label
  if hrs = 0 and mins = 0 and secs = 0 then
    shell(shutdown -s) 'shuts down the comp
  end if
  if secs = 0 then '##### the whole of this if statement basically
    if mins = 0 then '#### just minuses 1 from Label1 everytime
      if not hrs = 0 then '# the timer clicks over.
        hrs = hrs - 1
      end if
      mins = 59
    else
      mins = mins - 1
    end if
    secs = 59
  else
    secs = secs - 1
  end if
  label1 = "0" & hrs & ":" & iif(mins < 10, "0" & mins, mins) & ":" & iif(secs < 10, "0" & secs, secs) 'displays the timer as "00:00:00" type format
end sub

Stuff to know:
Label1 is the label that will be displaying the time (00:00:00).
Set timer interval to 1000.
You will need some function or way of inputting the time to the label. I suggest making a textbox where the user puts the amount of seconds he/she wants to wait then have them press a command button to format and transfer the seconds into a HR:MIN:SEC format into that label.
 
Code:
Shell ("Shutdown -s -t 5")
thats waits 5 seconds before shutting down. (i think it displays the count down im not sure).

But if you must have the 00:00:00 format its pretty simple and just basic maths. i will be doing this free hand so there could be errors but you should be able to fix them up yourself.
I'll try and comment it as best i can (i hate commenting)

Code:
private sub timer1_timer()
  Dim Hrs as long, Mins as long, Secs as long 'deccy's
  hrs = val(split(label1.":")(0)) 'gets hrs remaining from the label
  mins = val(split(label1.":")(1)) 'gets mins remaining from the label
  secs = val(split(label1.":")(2)) 'gets secs remaining from the label
  if hrs = 0 and mins = 0 and secs = 0 then
    shell(shutdown -s) 'shuts down the comp
  end if
  if secs = 0 then '##### the whole of this if statement basically
    if mins = 0 then '#### just minuses 1 from Label1 everytime
      if not hrs = 0 then '# the timer clicks over.
        hrs = hrs - 1
      end if
      mins = 59
    else
      mins = mins - 1
    end if
    secs = 59
  else
    secs = secs - 1
  end if
  label1 = "0" & hrs & ":" & iif(mins < 10, "0" & mins, mins) & ":" & iif(secs < 10, "0" & secs, secs) 'displays the timer as "00:00:00" type format
end sub
Stuff to know:
Label1 is the label that will be displaying the time (00:00:00).
Set timer interval to 1000.
You will need some function or way of inputting the time to the label. I suggest making a textbox where the user puts the amount of seconds he/she wants to wait then have them press a command button to format and transfer the seconds into a HR:MIN:SEC format into that label.
OK thanks, Ill try it out and see what I get. Would it be possible for the user to submit the time as HH:MM:SS format?
 
Ehh getting some errors with the split statement. I asked the IPT teacher at school, and he seemed to be at an end as well. I've attached my project, perhaps you could correct it Covey? :)
 

Attachments

Runescape Gamblingrunescape gambling
Back
Top