|
-
May 11th, 2011, 05:59 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] problem stoping timer when i get popup message!
Hi all i got this code that supposed to stop timer1 and timer2 when i get a popup message from an external application that application form failed!
The problem is that when i get such popup the timer never stops automatically and i have to press Command6_Click few times until the timer2 and timer 3 stops!.(i know timer2 and timer 1 didn't stop because the form is getting re submitting over and over and i get that failed message popup again and again...) Could you guys tell me what i am doing wrong ? i want stop the timer1 and timer2 immediately when i get failed popup!Hope you guys help me solve this problem.Thanks
Code:
Private Sub Timer1_Timer()
Dim hParent As Long
Dim hChild As Long
'To find the Parent window
Do
hParent = FindWindow("#32770", "Welcome to application")
DoEvents
Loop Until hParent
If Not hParent = 0 Then
lngStatic = FindWindowEx(hParent, 0&, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
'If button found then click it.
If lngStatic <> 0 Then
'Now we clicked the button
''Call SendMessage(hChild, BM_CLICK, 0, 0)
Call SendMessageLong(lngStatic, WM_LBUTTONDOWN, 0&, 0&)
Call SendMessageLong(lngStatic, WM_LBUTTONUP, 0&, 0&)
End If
End If
End Sub
Private Sub Timer2_Timer()
Dim hParent2 As Long
'Do
hParent2 = FindWindow("#32770", "Registration Form")
' DoEvents
' Loop Until hParent
If Not hParent2 = 0 Then
Command2_Click '' is filling the form in external application
End If
End Sub
Private Sub Timer3_Timer()
Dim x As Long,
x = FindWindow("#32770", "The application form has failed")
If Not x = 0 Then
Command6_Click ' this function suppose to stop the timers but it doesn't !
'Timer1.Enabled = False
'Timer2.Enabled = False
End If
End Sub
Private Sub Command6_Click()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
-
May 11th, 2011, 06:20 AM
#2
Re: problem stoping timer when i get popup message!
if you only want the timer to run once you must disable it within the timer event, before or after the other code
you probably should not run the do - loop within the timer event
vb Code:
Private Sub Timer1_Timer() Dim hParent As Long Dim hChild As Long 'To find the Parent window ' Do hParent = FindWindow("#32770", "Welcome to application") ' DoEvents ' Loop Until hParent If Not hParent = 0 Then ' else do nothing, let the timer fire again lngStatic = FindWindowEx(hParent, 0&, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString) 'If button found then click it. If lngStatic <> 0 Then 'Now we clicked the button ''Call SendMessage(hChild, BM_CLICK, 0, 0) Call SendMessageLong(lngStatic, WM_LBUTTONDOWN, 0&, 0&) Call SendMessageLong(lngStatic, WM_LBUTTONUP, 0&, 0&) End If timer1.enabled = false ' window was found so stop timer End If End Sub
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 12th, 2011, 12:25 PM
#3
Thread Starter
Frenzied Member
Re: problem stoping timer when i get popup message!
Many thanks westconn1 disabling timer once i found the window realy solved the problem. Now i learned that after window found i should disable timer and and enable it in the next round when i load the application!
Code:
timer1.enabled = false ' window was found so stop timer
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
|