Results 1 to 16 of 16

Thread: timing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Smile timing

    How can I count down from a number in seconds exactly?
    My sister is always on the computer for too long now, and digging into my turn (sometimes by 1 hours 50 mins, as it was today) because we both have 1 computer with internet. As I have absolutelly no idea of what programme to make, apart from several complicated ones that I wont be able to do, I've decided to time her on the computer now. I hope it works, and It cant do that if you dont help me.
    thankyou
    i'm new so be nice

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: timing

    use a timer object and set the interval propertie to 1000, being 1000 ms, equal to 1 second.

    add a label to the form and put in the number of seconds you want to countdown from (if you prefer minutes, set the timer interval to 60000, making 60s, a minute)

    In the timer's timer event, put the following code
    VB Code:
    1. Private Sub Timer1_Timer()
    2.    Label1.Value = Val(Label1.Value) - 1
    3.    If Val(Label1.Value) = 0 Then
    4.       MsgBox("Time's Up")
    5.       Timer1.Enabled = False
    6.    End If
    7. End Sub
    Delete it. They just clutter threads anyway.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: timing

    Add Timer control, label (I named it lblTime) and use code below - it will calculate ellapsed seconds and show formated value (hh:nn:ss) in the label:
    Code:
    Option Explicit
    
    Dim strStartTime As String
    
    Private Sub Form_Load()
        strStartTime = Now
        lblTime.Caption = "00:00:00"
        Timer1.Interval = 1000 '1 second
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Dim lSecondsEllapsed As Long
    
        lSecondsEllapsed = DateDiff("s", strStartTime, Now)
        
        lblTime.Caption = Format(lSecondsEllapsed \ 3600, "00") & ":" & _
                          Format((lSecondsEllapsed \ 60) Mod 60, "00") & ":" & _
                          Format(lSecondsEllapsed Mod 60, "00")
    
    End Sub

  4. #4

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Smile Re: timing

    I did a timer that used 3 different labels, hour, minute and second with colons inbetween, and if my sister tries to restart the counter by reopening the programme, wont it just set two counters next to each other? I've only done visual basic for a couple of weeks so i'm not that experienced.

  6. #6
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: timing

    Or on the form_unload you can just have it set where it left off in the registry :P Then pick that up the next time it opens on the form_load
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: timing

    Heh, that's a great idea, k0zz.

    To the OP: Generally speaking, RhinoBull's method is the best one for this sort of thing.

    As an evil aside, given your stated purpose, what I might do is when the timer runs out, bring up an AlwaysOnTop form that fills the screen so she cannot continue to use the computer pretty much at all once her time expires. If you toss in k0zz's registry suggestion even a reboot won't help.

    All you'd need to do is add some sort of unlock password that lets the user "unlock" the computer by typing it into the AlwaysOnTop form.

    heh.

    If you think that would be fun, I can help you with all the complicated bits like using the registry and setting a form to be AlwaysOnTop and filling the screen.

  8. #8
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: timing

    Quote Originally Posted by RhinoBull
    On a second thought ... your sister may simply reopen your program to restart the counter...
    It's pretty easy to disallow ending a program unless some condition is true, like entering a valid password.

  9. #9
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: timing

    if she isn't too great with computers the easiest way would be to disable the showintaskbar property in IDE and to set the borderstyle 'none'.

    for as the task list (in the taskmanager), there was an easy way i don't remember...

    anyway, if you'd compile the application with a name like svchost.exe, you would already have hidden the program in the processes list as there are already 5 or 6 of that application there.

    on the desktop you simply add a shortcut to the application with a normal name.
    Delete it. They just clutter threads anyway.

  10. #10
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: timing

    a complete different way to do this, is give the app the time of day where your sisters time is up; kind of alarm clock like.

    again with a timer you would check every minute whether the time has been reached.

    the problem with this, though, is that you have to prevent her from changing the time, but that can also be solved by a more advanced close-by-handle function.

    also this would be easier to combine with the registry as the alarm time is a fixed value.
    Delete it. They just clutter threads anyway.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Question Re: timing

    Quote Originally Posted by TheBigB
    if she isn't too great with computers the easiest way would be to disable the showintaskbar property in IDE and to set the borderstyle 'none'.

    for as the task list (in the taskmanager), there was an easy way i don't remember...

    anyway, if you'd compile the application with a name like svchost.exe, you would already have hidden the program in the processes list as there are already 5 or 6 of that application there.

    on the desktop you simply add a shortcut to the application with a normal name.
    I've just checked in the task manager for svchost.exe, and its there, and it will run all the time, and its important for something. If I name the programme after it, will it damage the computer in any way, because the computer will think: wait, there are 2 svchost.exes here, and it might stop doing one of them in order to do the other one, wont that damage the computer in some way?

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: timing

    Quote Originally Posted by TheBigB
    ...anyway, if you'd compile the application with a name like svchost.exe....
    I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Re: timing

    Quote Originally Posted by RhinoBull
    I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.
    what would happen if you did do that?

  14. #14

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    Re: timing

    Quote Originally Posted by RhinoBull
    Try it to find out for yourself.
    but my computer might blow up, then there would be no point in making the programme anyway.

  16. #16
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: timing

    Quote Originally Posted by RhinoBull
    I'm sorry pal but that is the worst idea anyone could come up with - under no sircumstances you would want to mess with system's apps.
    why is that then?
    giving it that name will only mask it in the list.
    a more advanced user would be able to see that the svchost.exe running under a normal user (so not local service, networks service and system) would be the vb application.
    Delete it. They just clutter threads anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width