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

Need a continuous timer to count from 1 to 3?

Status
Not open for further replies.

spyder

Technical User
Jan 10, 2001
21
US
To begin with, I'm new to programming...
I need to add a timer to a project of mine that would continuously count from 1 to 3, and then repeat again, so that on the 2 count, I could have a particular procedure execute each time. Would I use a timer control with a text box (so I can see the actual count), and somehow loop it? Any suggestions?
 
Do you want to count from 1 to 3 or or execute a procedure every three seconds?

If you want to execute something every three seconds then set the interval on your timer to 3000. Then

Private Sub Timer1_Timer()
Call Sub_Procedure_Here
End Sub

I'm not sure why you want to see the count but if you have the interval set to three you may need another timer control to update the text box every second to show the count. Use a use some code in the second timer have a counter count from 1 to 3.
 
Put a timer control on your form. Set the interval for how often you want one of the procedures to run (seconds * 1000)
Then change the Text1.text to the name of the label or textbox to output the current value. Add the names of the procedures to run in each case to the select case statement. Set the timer's enabled property to true. Create a public variable named CounterVar (an integer) to hold the current count.
Code:
Private Sub Timer1_Timer() 
   Text1.Text = CounterVar 'show the current val 
   Select Case CounterVar 
      Case 1 
        'Run a procedure here 
      Case 2 
        'Run a procedure here 
      Case 3 
        'Run a procedure here 
   End Select 

   If CounterVar >= 3 Then 
      CounterVar = 1 
   ElseIf CounterVar = 2 Then 
      CounterVar = 3 
   ElseIf CounterVar = 1 Then 
      CounterVar = 2 
   End if 
 
End Sub
Ruairi

Could your manufacturing facility benefit from real time process monitoring? Would you like your employees to be able to see up to the minute goal and actual production?
For innovative, low cost solutions check out my website.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top