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!

timer problems, dont know how to use it

Status
Not open for further replies.

gnibbles

Programmer
Mar 15, 2000
79
CA
Im trying to read from the comm port 2 every 10 seconds or whenever i want and i want to use the timer to do it, i have all the code to read from the port i just dont know how to integrate it with the timer.

gnibbles
nturpin@excite.com
 
add a timer to your form, set it to be enabled (if you want it to start doing it as soon as the program starts)

interval is set in miliseconds, so 1000 = 1 seconds

and in the timer code, you type in the code you want it to do every time the interval is hit
you can start/stop the timer using TimerName.Enabled = True/False
Karl
kb244@kb244.com
Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

 
Dim i, j As Integer

Private Sub Form_Load()
init
End Sub

Public Sub init()
Timer1.Interval = 10000 '10 seconds
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
'as long as timer1 is enabled, your program jumps here
'every 10 seconds or whatever you set the interval to.

DoEvents 'safety valve.

For i = 1 To 1000
For j = 1 To 1000
Next j
Next i

'after executing the above code, your program will jump
'here again after 10 seconds.
End Sub

You may have to disable the timer once your code within the timer1_timer() sub starts executing and re-enable it upon completion. Ten seconds isn't very long depending upon what your code is doing.
 
gnibbles

wouldn't it be more reliable to use the oncomm event so that you can make sure you never miss any data?
Mike
michael.j.lacey@ntlworld.com
 
MIke

what is this oncomm command, because there is no documentation what so ever on the mscomm part of vb

gnibbles
nturpin@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top