Jump to content
Sign in to follow this  
gandalfthewhite

For Loop Question

Recommended Posts

gandalfthewhite

#include "IE.au3"
#include "file.au3"

dim $specialCharURL = "barnes[@)noble"
dim $searchString = "barnesandnoble"

dim $log = "6539"

$oIE = _IECreate($specialCharURL, 0, 1, 1, 0)

IF @error = 0 Then
    $oLinks = _IELinkGetCollection($oIE)                        
    $iNumLinks = @extended                          
    For $oLink In $oLinks                           
       IF(StringInStr($oLink.href, $searchString) <> 0) Then                          _FileWriteLog(@ScriptDir & "\"& $log &"_passed.txt", "The special characters in '" & $specialCharURL & "' opened the search page " & $actualResolvedURL & " and have links on the search page resolved as " & $searchString)
           ExitLoop                         
                   Elseif(?????) Then
          _FileWriteLog(@ScriptDir & "\"& $log &"_FAILED.txt", "The search page didnot have any links that were resolved to " & $searchString)
       EndIf
    Next
Else
    _FileWriteLog(@ScriptDir & "\"& $log &"_FAILED.txt", "Internet Explorer could not be opened")
EndIf

_IEQuit($oIE)

In the script above, where I have put ?????, I want to figure out a way to develop and expression inside that elseif statement. What I am intending to do it, to go through all the links in the page and look for a particular search string. But if that search string is not found and all the links have been searched, I report an error.

The elseif statement should check the total number of links (that I get through $iNumLinks) against the current iteration to see if the current iteration has reached the last link and still a match is not found. How do I find the current iteration for this for loop and hence how do I write this elseif statement?

Share this post


Link to post
Share on other sites
Xajar

Pulled this from the help files and made a few simple changes.

#include <IE.au3>

$Target_URL = 'www.google.com'
$Target_String = 'about.html'

$oIE = _IECreate ($Target_URL)
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended

$Link_Index = 0
$Link_Found = False

If @error = 0 Then
    For $oLink In $oLinks
        $Link_Index += 1
        If StringInStr($oLink.href,$Target_String) Then
            $Link_Found = True
            ConsoleWrite( 'Search String was found : ' & $oLink.href & @CRLF )
        ElseIf $Link_Index = $iNumLinks And $Link_Found = False Then
            ConsoleWrite( 'Search string was not found.' & @CRLF )
        EndIf
    Next
EndIf

Share this post


Link to post
Share on other sites
gandalfthewhite

Awesome xajar. Thanks for your help. This works for me.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.