Jury

For..In to array

5 posts in this topic

Is there a simple way to convert the results of a For ... In loop such as in the example  given for _IELinkGetCollection (below) into an array?  I want to sort and then delete duplicates of the resultant links before I navigate to them.

 

; Open browser with basic example, get link collection,
; loop through items and display the associated link URL references

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IE_Example("basic")
Local $oLinks = _IELinkGetCollection($oIE)
Local $iNumLinks = @extended

Local $sTxt = $iNumLinks & " links found" & @CRLF & @CRLF
For $oLink In $oLinks
    $sTxt &= $oLink.href & @CRLF
Next
MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt)

 

Share this post


Link to post
Share on other sites



one of possible ways

; Open browser with basic example, get link collection,
; loop through items and display the associated link URL references

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>

Local $oIE = _IE_Example("basic")
Local $oLinks = _IELinkGetCollection($oIE)
; Local $iNumLinks = @extended
Local $sTxt ; = $iNumLinks & " links found" & @CRLF & @CRLF

For $oLink In $oLinks
    $sTxt &= $oLink.href & @CR
Next
; MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt)
$sTxt = StringTrimRight($sTxt, 1) ; remove last @cr
Local $aArray = StringSplit($sTxt, @CR, 3) ; from string to array
$aArray = _ArrayUnique($aArray, 0, 0, 0, $ARRAYUNIQUE_NOCOUNT) ; remove duplicates
_ArraySort($aArray) ; sort the array
_ArrayDisplay($aArray)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Chimp,

Two things I can't find any mention of the flag $ARRAYUNIQUE_NOCOUNT and if I set this to 0 or 1 no array is displayed (or perhaps created?)

Thanks anyway

Share this post


Link to post
Share on other sites

I'm using last AutoIt v 3.3.14.2.

$ARRAYUNIQUE_NOCOUNT is set to 0, meaning don't return count in first element of the array.

try to use a new variable to store the "ArrayUnque" array

; Open browser with basic example, get link collection,
; loop through items and display the associated link URL references

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>

Local $oIE = _IE_Example("basic")
Local $oLinks = _IELinkGetCollection($oIE)
; Local $iNumLinks = @extended
Local $sTxt ; = $iNumLinks & " links found" & @CRLF & @CRLF

For $oLink In $oLinks
    $sTxt &= $oLink.href & @CR
Next
; MsgBox($MB_SYSTEMMODAL, "Link Info", $sTxt)
$sTxt = StringTrimRight($sTxt, 1) ; remove last @cr
Local $aArray = StringSplit($sTxt, @CR, 3) ; from string to array
local $aArray2 = _ArrayUnique($aArray, 0, 0, 0, 0) ; remove duplicates
_ArraySort($aArray2) ; sort the array
_ArrayDisplay($aArray2)

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Thanks again Chimp - it works without using the ArrayUnique line so I'll work on fixing that (I've used it before without a poblem somewhere)

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