Modify

Opened 10 years ago

Closed 10 years ago

#3166 closed Bug (Fixed)

Error in Arrays wiki

Reported by: lorenzo.santina.dev@… Owned by:
Milestone: Component: Documentation
Version: 3.3.14.2 Severity: None
Keywords: Cc:

Description

At wiki page:
https://www.autoitscript.com/wiki/Arrays#Arrays_in_Arrays

in the seciton Arrays in Arrays there is this sentence:

"The thing is, there is no way to directly access that array stored in the element. You have to go through a variable to get access to the embedded array which may make your code overly complicated and difficult to debug."

This is NOT true.

In fact you CAN directly access the array stored in an element of another array, without go through a variable, doing so:

($arr[0])[0] ;first element of the array stored in the first element of $arr

I rewrote the script example in that page:

Local $arr[3]

Local $a1[3] = [2, "a1-1","a1-2"]
Local $a2[3] = [2, "a2-1","a2-2"]

$arr[0] = 2
$arr[1] = $a1
$arr[2] = $a2

For $i = 1 to $arr[0]
    If IsArray($arr[$i]) Then
        For $j = 1 to ($arr[$i])[0]
            ConsoleWrite("($arr[" & $i & "])[" & $j & "] := " & ($arr[$i])[$j] & @LF)
        Next
    Else
        ConsoleWrite("!>Oops!, What happened? Expected an array!" & @LF)
    EndIf
Next

Please update the wiki

Attachments (0)

Change History (6)

comment:1 by J-Paul Mesnage, 10 years ago

I never thought such syntax

($arr[$i])[$j]

was legal.

Is it described in the standard Help?

comment:2 by lorenzo.santina.dev@…, 10 years ago

Yes, just found in AutoIt Language Reference..
Bottom of the page:
https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm

"Data types in Arrays"

$aArray[0] = 1
$aArray[1] = True
$aArray[2] = "Text"
$aArray[3] = $aAnotherArray

Local $aInternal[3] = ["A", "B", "C"] ; Declare an array
Local $aContainer[1] = [$aInternal] ; Declare a container array holding the first
$sString = ($aContainer[0])[1] ; $sString holds "B"
; Note the requirement to enclose the first array element definition in ( )

comment:3 by TheDcoder, 10 years ago

You can manually edit the wiki yourself by clicking edit link after the section's name (Here is the direct link for editing Arrays in Arrays)

in reply to:  2 comment:4 by J-Paul Mesnage, 10 years ago

Replying to lorenzo.santina.dev@…:

Yes, just found in AutoIt Language Reference..
Bottom of the page:
https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm

"Data types in Arrays"

$aArray[0] = 1
$aArray[1] = True
$aArray[2] = "Text"
$aArray[3] = $aAnotherArray

Local $aInternal[3] = ["A", "B", "C"] ; Declare an array
Local $aContainer[1] = [$aInternal] ; Declare a container array holding the first
$sString = ($aContainer[0])[1] ; $sString holds "B"
; Note the requirement to enclose the first array element definition in ( )

Well done, I never figure out it was so hard to find
Many thanks

Last edited 10 years ago by J-Paul Mesnage (previous) (diff)

in reply to:  3 comment:5 by lorenzo.santina@…, 10 years ago

Replying to TheDcoder:

You can manually edit the wiki yourself by clicking edit link after the section's name (Here is the direct link for editing Arrays in Arrays)

I can't see any "edit" button
If I try to login, none username is recognized and I can't find any registration page :/
If I open your link i can't obiously edit the text

comment:6 by Melba23, 10 years ago

Resolution: Fixed
Status: newclosed

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.