Results 1 to 3 of 3

Thread: [RESOLVED] problem stoping timer when i get popup message!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Private Sub Timer1_Timer()
    2. Dim hParent As Long
    3. Dim hChild As Long
    4.     'To find the Parent window
    5.  
    6.  
    7.   '       Do
    8.                    hParent = FindWindow("#32770", "Welcome to application")
    9.   '                DoEvents
    10.   '      Loop Until hParent
    11.  
    12.  
    13.     If Not hParent = 0 Then  ' else do nothing, let the timer fire again
    14.    
    15.        
    16.         lngStatic = FindWindowEx(hParent, 0&, "static", vbNullString)
    17.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    18.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    19.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    20.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    21.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    22.     lngStatic = FindWindowEx(hParent, lngStatic, "static", vbNullString)
    23.         'If button found then click it.
    24.         If lngStatic <> 0 Then
    25.             'Now we clicked the button
    26.             ''Call SendMessage(hChild, BM_CLICK, 0, 0)
    27.             Call SendMessageLong(lngStatic, WM_LBUTTONDOWN, 0&, 0&)
    28.             Call SendMessageLong(lngStatic, WM_LBUTTONUP, 0&, 0&)
    29.         End If
    30.         timer1.enabled = false    ' window was found so stop timer
    31.     End If
    32.  
    33.    
    34.  
    35. 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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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
  •  



Click Here to Expand Forum to Full Width