|
-
May 12th, 2011, 12:15 PM
#1
Thread Starter
Frenzied Member
How change timer interval if it already running ?
Hi all .I got command8 function that clicks a button(command1) every pre defined seconds (for example every Text16.Text=30 seconds)by the user.
I wonder how i can change timer4 interval inside timer3 when for example application form failed messagebox pops up ? I want some how inside timer3 make the time4 internal to 1 or 1.5 or 2 mins and after 2 min passed change the timer4 interval back to original value(orginal value 30 seconds)! (so my goal is after i get application failed meessagbox pops up i take 1.5 or 2 min timeout and then start clicking the button every 30 seconds again..).For example if 15 second is left so command1 get clicked and at this moment i get that failed popup box so i want the command1 get clicked after 1 or 1.5 or 2 min not after 15 seconds!
could any one show me how i can achieve that.Thanks
Code:
Private Sub Command8_Click()
If Command8.Caption = "Start" Then
Command8.Caption = "Reset"
Timer4.Interval = Val(Text16.Text * 1000)
Timer4.Enabled = True
Else: Timer4.Enabled = False
Command8.Caption = "Start"
Text16.SetFocus
ClickCount = 0
End If
End Sub
Private Sub Timer4_Timer()
ClickCount = ClickCount + 1
MaxClicks = Text17
Command1.Value = True ' command1 button is get click after this many seconds
Command1.Caption = "Clicked"
If ClickCount = MaxClicks Then
Timer4.Enabled = False
MsgBox "Maximum Clicks Reached"
ClickCount = 0
Command8.Caption = "Start"
End If
End Sub
Private Sub Timer3_Timer()
Dim X As Long, editx As Long
Dim button As Long
X = FindWindow("#32770", "Application form has failed")
If Not X = 0 Then
'Now i need to rest timer4 internet to 2 min
Timer3.Enabled = False ' window was found so stop timer
End If
End Sub
Last edited by tony007; May 12th, 2011 at 12:37 PM.
-
May 12th, 2011, 12:57 PM
#2
Re: How change timer interval if it already running ?
It can be changed at any time however depending on what timer does and if interval is very short it may create some side effect:
Code:
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub
Private Sub Command1_Click()
Timer1.Interval = Timer1.Interval + 500
End Sub
Private Sub Timer1_Timer()
Debug.Print Timer1.Interval
End Sub
-
May 12th, 2011, 01:15 PM
#3
Thread Starter
Frenzied Member
Re: How change timer interval if it already running ?
Thanks for you reply. how i can define 1 or 1.5 or 2 min timer interval ?
so 1 min will be Timer1.Interval = 60000 and 1.5 min will be Timer1.Interval = 90000 and 2 min Timer1.Interval = 120000?
I tried timer1interval=120000 for two min interval and i get this error(trying to change timer interval from 30 seconds to 2 min:
run-time error '380':
invalid property value
how to solve it ?
Last edited by tony007; May 12th, 2011 at 01:25 PM.
-
May 12th, 2011, 01:48 PM
#4
Re: How change timer interval if it already running ?
Max Interval is 1 minute (60000). If you need it longer than simply increment counter inside timer procedure and execute what you need when counter reaches certain value.
Search forum for samples - there are many out there.
-
May 12th, 2011, 02:17 PM
#5
Thread Starter
Frenzied Member
Re: How change timer interval if it already running ?
RhinoBull but how i should make my timer to work with both seconds and min ? as you see from this code it works with seconds how i should make it work in mins when cetain conditions applies for example application form fails ?
Code:
Private Sub Timer4_Timer()
ClickCount = ClickCount + 1
MaxClicks = Text17
Command1.Value = True ' command1 button is get click after this many seconds
Command1.Caption = "Clicked"
If ClickCount = MaxClicks Then
Timer4.Enabled = False
MsgBox "Maximum Clicks Reached"
ClickCount = 0
Command8.Caption = "Start"
End If
End Sub
Last edited by tony007; May 12th, 2011 at 02:42 PM.
-
May 12th, 2011, 11:59 PM
#6
Re: How change timer interval if it already running ?
Are you aware that a CommandButton's value is normally false and becomes true only at the instance of "click" and a uS later it's false again?
Edit: Sorry about that. I misread your code. I thought I saw...
Code:
If Command1.Value = True
Last edited by CDRIVE; May 13th, 2011 at 09:37 AM.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
May 13th, 2011, 07:40 AM
#7
Re: How change timer interval if it already running ?
 Originally Posted by tony007
...but how i should make my timer to work with both seconds and min ?
You want that for the same timer? You may [I guess] but it would require some sort of flag to be raised indicating interval "type" (second, minute).
If you need it by minutes then you'd have to set Interval = 60000 (1 minute) and then use counter inside timer_timer procedure to actually count the minutes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|