Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing a working digital clock on a form? Can it be done easily?

Status
Not open for further replies.

Jusfire

Programmer
Jan 18, 2002
31
US
Developing a call management database. I would like to provide users an active clock diplaying the current system time in their field of view on a form. Can this be done and how? I'm sure there must be some time of add-in to provide this function.

In addition, is there a method of providing a similar item being a timer/stopwatch (counting up) that would activate and display itself when a call is initiated.

Email solutions, comments, questions, etc....

jusfire@hotmail.com
 
'set the load event to call procedure

Private Sub Form_Load()
Form_Timer
End Sub

set the procedure to update your field.
Private Sub Form_Timer()
Me.TimerInterval = 1000
[Your Field Name] = Now()
End Sub

i found this under another thread.
 
Absolutely wonderful and simple! With the regional settings on 24-hour time 'Military Time' this accomplishes exactely what I needed for the clock portion of my question.

Thanks so very much for your assistance 'Senjen'. I searched but couldn't find anything in previous threads.

Now for the second part. The stopwatch item...
 
1)create an object on the form (a label works the best- assume it is called 'TimeOfDay')
2) set the time interval in the form (1000 works ok - the nember is in miliseconds)
3) add the following line in the on timer event of the form... TimeOfDay.caption = now()

this will update the time every second.
 
Jusfire,

Built a form with one label (L1), two textboxes (T1,T2), and one command button (C1). The key is capturing the time value when you want the Stopwatch/Timer to begin. In this example, the Tag property for T1 is used to do that.

On the Form's Load Event, ran
Code:
  Me.TimerInterval = 1000
  T1.Tag = ""
  T2 = ""
  C1.Caption = "Begin Timer"

On the Command button (C1) click event:
Code:
   If T1.Tag = "" Then
     T2 = T1
     T1.Tag = Now
     C1.Caption = "Stop Timer"
   Else
     T2 = T1
     T1.Tag = ""
     C1.Caption = "Begin Timer"
   End If

On the Form_Timer event, the following checks to see if the tag property for T1 has a value other than "". If it does, it means the user clicked the command button to start the timer. The difference between the current time and the time the button was clicked is calculated each second and displayed in T1.
Code:
  L1.Caption = Time 
     If T1.Tag <> &quot;&quot; Then
        T1 = Now - CDate(T1.Tag)
     Else
        T1 = &quot;&quot;
     End If

I hope this is helpful to you.
John

Use what you have,
Learn what you can,
Create what you need.
 
Sorry, should have mentioned that the text box formats were set to &quot;hh:nn:ss&quot; and that the label (L1) displays the current time.


John

Use what you have,
Learn what you can,
Create what you need.
 
Hi

Further to this - how can I have a clock on my form display the current time without the form being closed and opened again.

tee
 
tee,

Not sure what you mean. Do you want the clock form to remain visible while the user toggles between other forms or is your clock not updating properly?

1.) If the clock form is a popup form, it will stay visible and updating even while other forms are active. You could have it as a separate form off in a corner as long as it is not covered by other forms. Another idea would be to use it as a quasi Switchboard form by having it maximize on loading and everything else opens in front of it.

2.) If the clock is not updating properly, there's a problem with the events you've coded. On the form load even, run Me.TimerInterval = 1000 and on the form's timer event, run TextBoxName = Time or LabelName.Caption = Time.


HTH


John

Use what you have,
Learn what you can,
Create what you need.
 
One other thought. You could use the Form's caption property to display the current time. On the Timer Event, run
Code:
Me.Caption = &quot;The Name of My Form - &quot; & Time

Tee, I must say that I hope this thread has been helpful to you. I've learned an awful lot about working with Time and the Timer event from trying to figure it out.

Thanks!
John

Use what you have,
Learn what you can,
Create what you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top