Jump to content

Recommended Posts

Posted

Hello again dear AutoIt Community.

Today I have a problem regarding Arrays. The faulty code is shown below.

$oIE = _IECreate($idURL, 0, 1, 1, 0)
_IELoadWait($oIE)

$links = _IELinkGetCollection($oIE)

Global $aTxt[1]

Local $iIndex = 0

For $link in $links
   _ArrayInsert($aTxt, $iIndex, $link.innerText)
   $iIndex += 1
   ConsoleWrite("$Number of Texts (links) = " & $iIndex & @CRLF)
Next

If IsArray($aTxt) Then
   _ArrayDisplay($aTxt, "1D array")
EndIf

;This works
;If _ArrayFindAll($aTxt, "Fairy") Then
;   MsgBox(0, "Success", "Found all instances and saved it in an array (apparently), BUT WHERE?")
;EndIf

;This results in an error
Local $aiResult = _ArrayFindAll($aTxt, "Fairy")

If IsArray($aiResult) Then
   _ArrayDisplay($aiResult)
Else
   MsgBox(0, @error, "$aiResult is not an array." & @CRLF & "Error Code " & $aiResult)
EndIf

ConsoleWrite("The code executed without errors." & @CRLF)
Exit

The symptoms I'm experiencing are that I cannot get hold of an array that should have been created by "_ArrayFindAll". The only thing I'm presented with is an error code "-1" (sets the @error flag to non-zero).

I'd be very grateful for anyone willing to help out. Many Thanks in advance,

~Medallyon

Posted (edited)

Also to add, There is certainly at least a dozen of instances where the Substring "Fairy" appears, so that's not the problem as I see it.

Well, without the URL I could only throw shit on a wall, but you are improperly using the return of _arrayfindall()

 

You can't:

If _ArrayFindAll($aTxt, "Fairy") Then
       MsgBox(0, "Success", "Found all instances and saved it in an array (apparently), BUT WHERE?")
EndIf

Because that's not how the return of _ArrayFindAll Works.  Just look at this code:  

#include <Array.au3>

Global $aTxt[0]

_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"")

Local $iIndex = 0

If IsArray($aTxt) Then
   _ArrayDisplay($aTxt, "1D array")
EndIf

;This works
If _ArrayFindAll($aTxt, "Fairy") Then
       MsgBox(0, "Success", "Found all instances and saved it in an array (apparently), BUT WHERE?")
EndIf

;This results in an error
Local $aiResult = _ArrayFindAll($aTxt, "Fairy")

If IsArray($aiResult) Then
   _ArrayDisplay($aiResult)
Else
   MsgBox(0, @error, "$aiResult is not an array." & @CRLF & "Error Code " & $aiResult)
EndIf

ConsoleWrite("The code executed without errors." & @CRLF)
Exit

Clearly there is no "Fairy" in the array, but the message box displays.

 

This works just fine:

#include <Array.au3>

Global $aTxt[0]

_ArrayAdd($aTxt,"Fairy")
_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"Fairy")
_ArrayAdd($aTxt,"")
_ArrayAdd($aTxt,"Fairy")

Local $iIndex = 0

If IsArray($aTxt) Then
   _ArrayDisplay($aTxt, "1D array")
EndIf

;This results in an error
Local $aiResult = _ArrayFindAll($aTxt, "Fairy")

If IsArray($aiResult) Then
   _ArrayDisplay($aiResult)
Else
   MsgBox(0, @error, "$aiResult is not an array." & @CRLF & "Error Code " & $aiResult)
EndIf

ConsoleWrite("The code executed without errors." & @CRLF)
Exit

So clearly the problem is the wall. (your source array)

Edited by kaisies

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
×
×
  • Create New...