English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Im trying to make a clock in VBEE2008 and it dosent work. I have everything set up. The timer is set to an interval of 100,and in my project i have 2 labels. 1 says Time: and the other(next to it) is left blank (i spaced so its still there) and for the code in Title it is

Label1.Caption= Time

Well i get errors,Caption dosent work and for time it has to be time of day. But what do i substitute for caption? Do i have to do timercode?

2007-12-31 12:56:29 · 3 answers · asked by . 3 in Computers & Internet Programming & Design

3 answers

Set a timer interval to 60,000
Within the timer

OnTimer
Label1.Caption = Format(Now(), "hh:mm:ss")

2007-12-31 13:03:16 · answer #1 · answered by LaCostaSteve 2 · 0 1

I haven't tried the 2008 version yet but you can try some of the following things.

1. make sure you are enabling your timer. The timer will not work unless its enabled property is set to true.

2. If your code is performing a loop which is taking a long time, the program will not execute code from other events until the current code section (event) completes. To allow the program to execute code from other events while it is processing a loop you will need to call the following :

my.Application.DoEvents

DoEvents is placed within the loop and when it is executed it will allow the program to temporarily branch away from the loop to handle any outstanding events (like a timer tick).

EDIT:
Normally you would use the timer tick event to update the label with the current time when the timer interval expires.

All other events in the program execute quickly (no loops or short loops) so that other events will have a chance to execute.

NOTE: Changing the contents of a caption or text property is an EVENT which also has to be allowed to execute in order for you to see the changes updated to the screen.

If you are writting code which is continously looping within an event like a button click you are preventing these events from being properly handled until either a DoEvents is called or the loop finishes and the button event completes. Upon completion of the button event the other events will be allowed to fire.

END EDIT:

3.
Timer intervals are in milliseconds (1/1000th of a second) so 1000 equals 1 second. The 100 interval is 1/10th of a second and could be increased to 500 or 1/2 a second. THis will increase performance or your program by not repeatedly triggering the timer 10 times per second.

4 you can capture the date time using the Now() function. I preferr to load values into variables instead of mashing everthing into a single line.

Dim myTimeStamp As DateTime
Dim str As String

myTimeStamp = System.DateTime.Now
str = Format(myTimeStamp , "hh:mm:ss")

label1.Text = str

all of the above can be mashed into a single line
label1.Text = format(now(),"hh:mm:ss")



5.) VB2008 may have a Caption property for the label. Try using the Text property (like VB2005) to place strings into the label for display

2007-12-31 21:28:11 · answer #2 · answered by MarkG 7 · 0 0

This works in VB express 2005:

Label1.Text = FormatDateTime(Now.Hour & ":" & Now.Minute & ":" & Now.Second)

2007-12-31 21:11:08 · answer #3 · answered by rod 6 · 0 0

fedest.com, questions and answers