Results 1 to 10 of 10

Thread: How do you make a VB chronometer/clock?

  1. #1
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default How do you make a VB chronometer/clock?

    You may have read about my VB project that was causing me a lot of problems. I have solved all of my problems except one.

    When the user logs in I want a clock to start. When they log out it will stop. This is to record how long they have been working for.

    I have no idea how I do this.

  2. #2
    Member Member Phatose's Avatar
    Join Date
    Dec 2003
    Location
    PA, USA
    Posts
    591

    Default Re: How do you make a VB chronometer/clock?

    On login:

    Dim Logintime as Date = now();


    On logout;
    TextBox1.Text = Now().Subtract(Logintime).ToString

  3. #3
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: How do you make a VB chronometer/clock?

    Thanks , but that is not quite what I am looking for.

    I need a text box or label that says 00:00:00 when the user logs in. Then it acts like a stopwatch, increasing until the user logs out.

  4. #4
    Member Member Phatose's Avatar
    Join Date
    Dec 2003
    Location
    PA, USA
    Posts
    591

    Default Re: How do you make a VB chronometer/clock?

    OK then, here's how you do that.


    First, add a timer control to your form. It's in windows forms like the textboxes and whatnot. Presumably you'll want to set the interval to 1000 (since it's in MS), and enabled=false. At the top, in the form itself dim a logintime variable as a date.



    In your login code, do this:

    logintime = now
    timer1.enabled = true

    and on logout, presumably
    timer1.enabled = false



    your timer1 tick event code should be like:

    TextBox1.Text = Format(Now.Subtract(logintime).Hours, "00") & ":" & Format(Now.Subtract(logintime).Minutes, "00") & ":" & Format(Now.Subtract(logintime).Seconds, "00")

  5. #5

    Default Re: How do you make a VB chronometer/clock?

    Would java be ok?

    Code:
    <head>
    <script>
    <!--
    //
      var milisec = 0;
      var seconds = 0;
    
    function display(){
      if (milisec>=9){
         milisec=0
         seconds+=1
      }
      else
         milisec+=1
         document.counter.ShambleS.value = seconds + "." + milisec;
         setTimeout("display()",100);
      }
    
    -->
    </script>
    </head>
    
    <body onload="display();">
    
    <form name="counter">
    <input type="text" size="10" name="ShambleS">
    </form>
    I just noticed...
    i think you want it to Log how long people were there.
    Not just display it for their benafit...
    and you want it in VB.
    So i cant help i dont think.

    But if the Java script is good enough..

    You can add more variables your self..

    I.e
    var mins = 0;
    var hours = 0;

    For mins and hours...

    then you can add
    if (seconds>=60).....
    and then the diferent variables there of..

    youd also need to change This...

    document.counter.ShambleS.value = seconds + "." + milisec;

    to something like
    document.counter.ShambleS.value = hours + "." + mins + "." + seconds + "." + milisec;

    To add the extra decimal points in the clock counter..
    "the words are the same as the names you gave your variables"

    "note: .counter.ShambleS. are related to the form name and input type name. and can be changed to any thing you like (but they need to be the same name in both)"

    But like i said.
    i doubt its what you want.
    Last edited by Just A Girl; 02-28-2006 at 21:41.

  6. #6
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: How do you make a VB chronometer/clock?

    It sort works. It is counting, only the format does not work.

    I had to play around with it a bit.

    TextBox1.Text = Format(Now.Subtract(logintime).Hours, "00") & ":" & Format(Now.Subtract(logintime).Minutes, "00") & ":" & Format(Now.Subtract(logintime).Seconds, "00")

    First I changed the name of the text box to txtTimeWorked.
    The ".Subtract" does not work so replaced them with "-".
    Then the ".Hours", ".Minutes" and ".Seconds" caused a "Expected: list seperator or )" error.

    Then it looked like this:
    Private Sub Timer1_Timer()
    txtTimeWorked.Text = Format(Now - (Logintime), Hours"00") & ":" & Format(Now - (Logintime), Minutes"00") & ":" & Format(Now - (Logintime), Seconds"00")
    End Sub

    It said "Expected: list seperator or )".

    Now it looks like this:

    Private Sub Timer1_Timer()
    txtTimeWorked.Text = Format(Now - (Logintime), Hours("00")) & ":" & Format(Now - (Logintime), Minutes("00")) & ":" & Format(Now - (Logintime), Seconds("00"))
    End Sub

    The bits in bold are causing problems. It says "sub or function not defined".

  7. #7
    Member Member Phatose's Avatar
    Join Date
    Dec 2003
    Location
    PA, USA
    Posts
    591

    Default Re: How do you make a VB chronometer/clock?

    Are those commas actually commas, or periods like they were in my post?

  8. #8
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: How do you make a VB chronometer/clock?

    Are those commas actually commas, or periods like they were in my post?
    They are commas.

    I just realised that the commas should after the hours, minutes and seconds, not is front of them.

    The periods cause an "Expected: list seperator or )" error. So does hours, minutes and seconds.

    The timer code looks like this:

    Private Sub Timer1_Timer()

    txtTimeWorked.Text = Format(Now - (Logintime)hours, "00") & ":" & Format(Now - (Logintime)minutes, "00") & ":" & Format(Now - (Logintime)seconds, "00")

    End Sub

  9. #9
    Time Lord Member The_Doctor's Avatar
    Join Date
    Oct 2004
    Location
    The TARDIS
    Posts
    2,040

    Default Re: How do you make a VB chronometer/clock?

    I continued messing around with the code and got it working. It was a lot shorter than what was posted.

    So, a big thank you to Phatose.

    Would java be ok?
    Maybe next year.

  10. #10
    Member Member Phatose's Avatar
    Join Date
    Dec 2003
    Location
    PA, USA
    Posts
    591

    Default Re: How do you make a VB chronometer/clock?

    Glad to hear you got it working.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO