?
Solved

Waiting on previous link click

Posted on 2005-05-08
8
Medium Priority
?
255 Views
Last Modified: 2010-04-17
I want this bit of code to wait on a click or document compelete event to fire prior to continuing.

If InStr(1, Trim$(ie.document.documentElement.innerText), "Click here", vbTextCompare) <> 1 Then
For Each link In ie.document.links

    If Trim$(link.innerText) = "Click here" Then link.Click
     'its clicking too fast here almost there though
            Next

There are heaps of click here's on this page, and I want it to wait until the previous click here is done until the next click here fires. It seems to be going too fast and clicking them all without actually waiting.

I had this, but it didn't change anything,

If InStr(1, Trim$(ie.document.documentElement.innerText), "Click here", vbTextCompare) <> 1 Then
For Each link In ie.document.links

    If Trim$(link.innerText) = "Click here" Then link.Click
     'its clicking too fast here almost there though
            Next
              complete = False
        time = Now
Do While complete = False
    DoEvents
        If (DateDiff("s", time, Now) > 30) Then
            Exit Do
        End If
    Loop

But I think the Next event :

    If Trim$(link.innerText) = "Click here" Then link.Click
     'its clicking too fast here almost there though
            Next

Is causing it to click all the links with Click here until it reaches the last one, and that's not exactly what I want.

Just want to slow it down where my comment is until it finishes loading!

Thanks In Advance for your participation

0
Comment
Question by:TOC-Fried
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 13956911
The simplest thing to do is ignore clicks while processing one of them.  Create flag:
bool ImBusy=false;

Upon entry to a click handler:
{
if (ImBusy) return;
ImBusy=true;
...
ImBusy=false;
return;
}

If you want the clicks to be remembered and processed in turn, you'll have to create the equivalent of a mini job queue
0
 
LVL 3

Author Comment

by:TOC-Fried
ID: 13957180
I think I posted this is programming? It was intended for Visual Basic, But anyway,

I am seeking to do this with visual basic. No Idea what language you were pointing at. Sorry about that.

Still looking for a method of doing this.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13957229
Something like this then...

Option Explicit

Private WithEvents IE As InternetExplorer
Private pageComplete As Boolean

Private Sub Form_Load()
   Set IE = CreatObject("InternetExplorer.Application")
   ' ...
End Sub

Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    pageComplete = True ' toggle your flag
End Sub

Private Sub Foo()
    pageComplete = False ' reset your flag
   
    ' click your link...
   
    ' wait for you flag
    While Not pageComplete
        DoEvents
    Wend
   
    ' do something else...
End Sub
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:TOC-Fried
ID: 13957254
One last small question.

Can that line of code go between the click and Next statement?

For Each link In ie.document.links
pageComplete = False
    If Trim$(link.innerText) = "Remove Me From Interest List" Then link.Click
           
     Do While pageComplete = False
        DoEvents
    Loop

     Next

Or is it:


For Each link In ie.document.links
pageComplete = False
    If Trim$(link.innerText) = "Click here" Then link.Click
                 Next
     Do While pageComplete = False
        DoEvents
    Loop

That way?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13959014
Your first version is correct.
0
 
LVL 3

Author Comment

by:TOC-Fried
ID: 13959547
No Joy..

It sits and idles doing nothing,

I am also already in a while .. wend operation, so i converted it to a Do while .. Loop operation and it still just sits and idles on the page. Not sure what's happening..

If InStr(1, Trim$(ie.document.documentElement.innerText), "Remove Me From Interest List", vbTextCompare) <> 1 Then
For Each link In ie.document.links
pagecomplete = False
    If Trim$(link.innerText) = "Remove Me From Interest List" Then link.Click
           
While Not pagecomplete
        DoEvents
    Wend

     Next

  This sits idle on the page and not clicking anything.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 375 total points
ID: 13960177
Change your If statement to this:

    If Trim$(link.innerText) = "Remove Me From Interest List" Then
        link.Click        
        Do While pageComplete = False
            DoEvents
        Loop
    End If

This is because if the innerText was not "Remove Me From Interest List" then it would get stuck in the Do...While loop.
0
 
LVL 3

Author Comment

by:TOC-Fried
ID: 13983152
I have a new question opened, based on this code. Will increase the points because you have helped so much.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question