Results 1 to 5 of 5

Thread: Webbrowser: Need help on delays inside the loop

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    124

    Question Webbrowser: Need help on delays inside the loop

    Hi everyone!

    I have a webbrowser control that opens a website and automatically fill in the textboxes on the forms. I am done with that part but im having problems with the loop.

    The data are stored in the database where i populate it using Msflexgrid. And i use two textboxes for ranges like process 1-5 or 10-20... etc coz i have more than 10,000 records.

    I want to leave my computer to process it but for the sake of testing i put number ranges that is incorporated in my loop.


    Code:
    Dim x As Long ' loop counter
    
    tempnum = CLng(txtFrom.Text)
    
    For x = CLng(txtFrom.Text) To CLng(txtTo.Text)
    
        With WebBrowser1
            .Document.All("Add").Click
    
            ' error on this part coz the above code is not yet completed
            .Document.All("Firstname").Value = MSFlexGrid1.TextMatrix(tempnum, 1) 
            .Document.All("Lastname").Value = MSFlexGrid1.TextMatrix(tempnum, 2)
            .Document.All("Save").Click
            tempnum = tempnum + 1
        End With
    Next x

    I'm having problems with the click event coz it will not wait for the document to complete before firing the next command. Is there a workaround for this delay without moving the rest of the function to "WebBrowser1_DocumentComplete" event?

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Webbrowser: Need help on delays inside the loop

    There are several possible solutions. The easiest to try is

    Code:
    Dim x As Long ' loop counter
    
    tempnum = CLng(txtFrom.Text)
    
    For x = CLng(txtFrom.Text) To CLng(txtTo.Text)
    
        With WebBrowser1
            .Document.All("Add").Click
            DoEvents
    
            ' error on this part coz the above code is not yet completed
            .Document.All("Firstname").Value = MSFlexGrid1.TextMatrix(tempnum, 1) 
            .Document.All("Lastname").Value = MSFlexGrid1.TextMatrix(tempnum, 2)
            .Document.All("Save").Click
            tempnum = tempnum + 1
        End With
    Next x

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    124

    Re: Webbrowser: Need help on delays inside the loop

    I've tried it. it will not work.

    Is there a workaround for usinga a delay without moving the rest of the function to "WebBrowser1_DocumentComplete" event?

    like this for example. it works with no prob.

    Code:
    Dim x As Long ' loop counter
    
    tempnum = CLng(txtFrom.Text)
    
    For x = CLng(txtFrom.Text) To CLng(txtTo.Text)
    
        With WebBrowser1
            .Document.All("Add").Click       'clicking add button
                                                     'the function is located
                                                     'on document complete below
            .Document.All("Save").Click     'clicking save button
            tempnum = tempnum + 1
        End With
    Next x
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    
        If (pDisp Is WebBrowser1.Object) Then
            If URL = "https://www.expected_URL_To_Trigger_A_Function.com" Then
                 .Document.All("Firstname").Value = MSFlexGrid1.TextMatrix(tempnum, 1) 
            .Document.All("Lastname").Value = MSFlexGrid1.TextMatrix(tempnum, 2)
    
            End If
        End If
    End Sub
    The problem with this is I have a loop is rhere any other way for the next command to wait until document is completed?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Webbrowser: Need help on delays inside the loop

    Quote Originally Posted by Erroneous
    The problem with this is I have a loop is rhere any other way for the next command to wait until document is completed?
    Define "completed"

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    124

    Re: Webbrowser: Need help on delays inside the loop

    completed as in "html document is completely loaded" before firing the next command.

    By the way, im browsing a secure page https and it seems that some button is not responding to what its suppose to do. Sometimes I need to hit F5 to refresh it and it will be ok. Is there a tip when using secure pages?

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