dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Keeping Accurate Time In VB

I developed a CBT project which required the user to read large amounts of text. I wanted to prompt the user to take a break after a period of time. The problem with the VB timer is that it lasts just over a minute. I used the API function GetCurrentTime(), which records the milliseconds since Windows was started. Place a Timer control on the form that starts the application (make sure that this form remains loaded throughout the application). Place this code in the Declarations section of the form:
 Dim Start&, Elapsed&
Declare Function GetCurrentTime& Lib "User" () 
The Form_Load event of this form must also contain this code:
 Start = GetCurrentTime
This routine sets the Timer interval to about a minute.
 Sub Timer1_Timer ()

	Dim MsgText$

	Elapsed = GetCurrentTime()
	' if 10 minutes has elapsed since 
	' the program was started
	' or the last msgbox was displayed
	If Elapsed - Start >= 600000 Then ' 10 minutes
		MsgText = "Give your eyes a rest. _
			Take a 5 minute break."
		MsgBox MsgText, 16, "Take A Break"
		' however long the msgbox is on the screen
		' the timer is effectively set to 0 when the
		' user presses OK
		Elapsed = GetCurrentTime()
		Start = Elapsed
		Elapsed = 0
	End If
End Sub
David Mawson
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date