Results 1 to 5 of 5

Thread: [RESOLVED] My code is working only when I toggle a breakpoint and STEP into code

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Resolved [RESOLVED] My code is working only when I toggle a breakpoint and STEP into code

    The following code launches internet explorer on the google webpage. Then a routine confirms that the IE windows was opened AND found.

    Code:
    Call proLaunchIE
    
    Public Sub proLaunchIE()
        Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE www.google.com", vbMaximizedFocus
        
        Dim booIEWasFound As Boolean
        For i = 0 To 20
            If fctIEHasFinishedLoading("Google") = True Then
                'loading SUCCESSFUL
                booIEWasFound = True
                Exit For
            End If
        Next i
        
        If booIEWasFound = False Then
            MsgBox "String 'google' not found"
            Exit Sub
        End If
    End Sub
    
    
    Public Function fctIEHasFinishedLoading(strWindowCaption As String) As Boolean
        Dim strWindowCaptionFound As String
        
        Call proWaitWithSleep(1000)
        strWindowCaptionFound = (GetCaption$(DLHFindWin&(frmForm, strWindowCaption, False)))
    
        If strWindowCaptionFound <> "" Then
            fctIEHasFinishedLoading = True
        Else
            Debug.Print "window-caption not found"
        End If
    End Function
    
    
    Public Function GetCaption(lhWnd As Long) As String
    
    Dim sA As String, lLen As Long
    
       lLen& = GetWindowTextLength(lhWnd&)
    
          sA$ = String(lLen&, 0&)
    
       Call GetWindowText(lhWnd&, sA$, lLen& + 1)
       GetCaption$ = sA$
        DoEvents
    End Function
    
    Public Function DLHFindWin(frm As Form, WinTitle As String, _
    CaseSensitive As Boolean) As Long
    
    Dim lhWnd As Long, sA As String
    
       lhWnd& = frm.hwnd
    
    
    Do
    
       DoEvents
          If lhWnd& = 0 Then Exit Do
             If CaseSensitive = False Then
                 sA$ = LCase$(GetCaption(lhWnd&))
                 WinTitle$ = LCase$(WinTitle$)
             Else
                 sA$ = GetCaption(lhWnd&)
             End If
    
           If InStr(sA$, WinTitle$) Then
              DLHFindWin& = lhWnd&
              Exit Do
           Else
             DLHFindWin& = 0
           End If
    
           lhWnd& = GetNextWindow(lhWnd&, 2)
    
    Loop
    End Function
    
    
    Public Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
        Dim sClass As String * 255
        Call GetClassName(hwnd, sClass, 255)
        If Left(sClass, 4) = "Edit" Then
            hwndCONTROL = hwnd
            Exit Function 'the first "edit" field found is the one I need - I can quit function
        End If
        EnumProc = hwnd
    End Function
    This code will work ONLY if I toggle a breakpoint in the proLaunchIE procedure. I can simply CTRL-BREAK into code, then press F5 and it'll find the "google" IE window. But won't find it without user interaction. It will simply end the loop without finding IE. I think this is weird. Anyone with an idea what is causing that?

    Tried putting "DoEvents" here and there but it didn't help.

    Thank you!
    Last edited by Krass; Aug 1st, 2018 at 08:44 AM.
    Chris

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