VS 2010 Loop Troubles-VBForums
Results 1 to 2 of 2

Thread: Loop Troubles

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Location
    United Kingdom
    Posts
    20

    Unhappy Loop Troubles

    I am new to VB and I am checking for a confirmation link in an email the page automatically refreshes so I do not need to worry about clicking refresh but I'm guessing this attempt at a loop I done is not right lol well it just crashes my program. All I want to do is keep checking the web page for that element say every 15 seconds or something and when it finds it to continue with the code I am currently trying

    Code:
    Dim emailpageelements As HtmlElementCollection = WebBrowser2.Document.GetElementsByTagName("a")
            Dim complete = True
                For Each emailver As HtmlElement In emailpageelements
                Do
                    System.Threading.Thread.Sleep(6000)
                    If InStr(emailver.InnerHtml, "https://twitter.com/account/confirm_email/") Then
                        complete = True
                    End If
                Loop Until complete
    I know I am probably miles off but I did try and I have spent the last day reading on loops and trying to figure out conditions and that however it just didn't click as I was unable to find any examples which I could relate to and use bit of to figure it out for myself basically I learn using examples and getting hands on better then reading (which of course I do read and research it would be impossible if I didn't

    If there is someone out there that could help me put this right I would be ever so grateful

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    8,425

    Re: Loop Troubles

    For Each requires a Next at the other end

    If I understand correctly what you are trying to do you need to move the Do and the Sleep above the For Each and add a Next before the Loop. You may also want to put an Exit For in there when you find your match.

    Code:
    Dim emailpageelements As HtmlElementCollection = WebBrowser2.Document.GetElementsByTagName("a")
    Dim complete = True
        Do
            System.Threading.Thread.Sleep(6000)
            For Each emailver As HtmlElement In emailpageelements
                 If InStr(emailver.InnerHtml, "https://twitter.com/account/confirm_email/") Then
                     complete = True
                     Exit For
                 End If
            Next
        Loop Until complete
    Last edited by DataMiser; Feb 22nd, 2012 at 08:55 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.