Jump to content

For..In to array


Jury
 Share

Recommended Posts

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)

 

Link to comment
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)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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)

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...