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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My clock display dosen't Work

Status
Not open for further replies.

Terence

Technical User
Feb 22, 2001
30
US
Okay here i am again. I am trying to display through a label on a form the time from the computers clock. I beleive the function is "now" and this is the code i have for it.

Option Explicit
---------------------------------------------------------------------------------------------------
sub clock()

label1.caption = Format (Now, "h:mm:ss Am/PM")

End sub
---------------------------------------------------------------------------------------------------
Now as you can see this dosen't work because i am not loading the Sub clock()
If i put the "clock" in the form_load() sub it will run the instant i load the form and that is all. What am I missing, i can't seem to find the answer i am looking for in any of my books...?????

really appreciate the help, thanks again......... :cool:
 
set a Timer ,interval 10

Private Sub Timer1_Timer()
Label1 = Now
End Sub
Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
okay, here are the goods! i finally got the situation in hand thanks to all that helped with the "time function" and this thread that was also causing the same problem. as i am new to this as well i see there are others i will explain what is needed, what i needed as i am a little slower grasping this.

Just as it was pointed out to me, to make any timer or clock or date function work you need the "Time object" from the toolbar selected and added to the main form that you will run with your program. This is what enables the time functions to operate (behind the scenes). In your program you need to make a Sub like " Sub Timer1_timer()".
then add your code in this to do what is required. The other important requirment is the "interval" setting for the properties of the Timer1. It is set at a default of "0" and this must be changed in order for this to run. If you are using VB6 when you highlight this in the properties box, it will tell you what this means. To make my "clock" work on my form i wrote this code:

Sub Timer1_timer()

' i used a label to display the time

label1=time() ' this will use a default setting of the time and dispaly it in the label
' caption box
' you can format the time to display how you like by doing this

label1=format (now, "h:mm:ss") ' use the F1 key to get all the different formats

end sub

Keep up the good work, pro's and never quit! s-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top