Roku
Roku

Reputation: 69

Passing Variable value to _IENavigate Autoit

I have an array called $urls which holds URLs. I want to use _IENavigate in a For-loop to visit each of those URLs, but don't know how to use an array with _IENavigate.

This is what I have so far:

If Not _FileReadToArray("\urls.txt", $urls) Then
    MsgBox(4096, "Error", " Error reading log to Array. Error:" & @error)
    Exit
EndIf

For $u = 1 to $urls[0]
    _IENavigate($mIE, $urls)
Next

Upvotes: 0

Views: 408

Answers (2)

Samoth
Samoth

Reputation: 1707

Matt is correct. He's actually adapting your code structure and providing a working example.

As long as you don't have to deal with the indexes of the Array inside of your loop, it's cleaner not to use the size of the array in the first element and then use a For ... In ... loop:

For $url In $urls
    _IENavigate($mIE, $urls)
Next 

To remove the first element, you could #include <Array.au3> and use _ArrayDelete($urls, 0). But I'd rather read in the file with the URLs without the size stored as the first element:

$urls = StringSplit(StringStripCR(FileRead("urls.txt")), @LF, 2)

- so you don't have to deal with the first element and you are split up by lines already. You can still use UBound($urls) to find out about the success.

And just a hint: Use indentation to make your code more readable.

Upvotes: 1

Matt
Matt

Reputation: 7160

To access array element number N you use $aArray[N].

Local $aArray[6] = [5, "Hello", "World", "Foo", "Bar", "Goodbye"]

For $i = 1 To $aArray[0]
    ConsoleWrite(  $aArray[$i]   & @LF)
Next

So in your above example, you want to use $urls[$u] within the For...Next loop.

Upvotes: 1

Related Questions