Timers

Discussion in 'Archives' started by Osmosis, May 27, 2007.

Timers
  1. Unread #1 - May 27, 2007 at 5:24 AM
  2. Osmosis
    Joined:
    Apr 29, 2005
    Posts:
    2,695
    Referrals:
    2
    Sythe Gold:
    0

    Osmosis Retired Australian Mod
    Banned

    Timers

    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.
     
  3. Unread #2 - May 27, 2007 at 9:06 AM
  4. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Timers

    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.
     
  5. Unread #3 - May 27, 2007 at 9:33 AM
  6. 17th Alley
    Joined:
    Jan 25, 2007
    Posts:
    290
    Referrals:
    0
    Sythe Gold:
    0

    17th Alley Forum Addict

    Timers

    Just make a .bat file like Covey said. You can then try to make that .bat file always execute on startup. regedit. Ur trying to make a virus, right? :D
     
  7. Unread #4 - May 27, 2007 at 9:48 AM
  8. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Timers

    i never said make a .bat file
     
  9. Unread #5 - May 28, 2007 at 2:17 AM
  10. Osmosis
    Joined:
    Apr 29, 2005
    Posts:
    2,695
    Referrals:
    2
    Sythe Gold:
    0

    Osmosis Retired Australian Mod
    Banned

    Timers

    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?
     
  11. Unread #6 - May 28, 2007 at 3:45 AM
  12. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Timers

    try something like:
    Code:
    format()
    or
    formattime()
     
  13. Unread #7 - May 29, 2007 at 2:44 AM
  14. Osmosis
    Joined:
    Apr 29, 2005
    Posts:
    2,695
    Referrals:
    2
    Sythe Gold:
    0

    Osmosis Retired Australian Mod
    Banned

    Timers

    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? :)
     

    Attached Files:

    • SM.zip
      File size:
      4.1 KB
      Views:
      4
< OMFG! need a lot of help please!!!!=( | Is america going to hell? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site