Jump to content

question about array within array


 Share

Recommended Posts

From the Autoit documentation, under the "variables" link I read:

It was said that an Array contains only one datatype of the same type. But technically speaking, a Variant in AutoIt can contain anything from a number to a boolean value. So an AutoIt-Array could also contain different types, even other Arrays:

$Array[0]=1
$Array[1]=true
$Array[2]="Text"
$Array[3]=$AnotherArray

 

Well, now if I have a simple 1D array, and one element of this contains another 1D array, how can I access the elements of the "nested" array?

 

Can I access $AnotherArray[2] directly from within $Array[3] in the following example?

Dim $AnotherArray[5] = ["zero", "one", "two", "three", "four"]
Dim $Array[4]

$Array[0] = 1
$Array[1] = True
$Array[2] = "Text"
$Array[3] = $AnotherArray

ConsoleWrite($Array[3][2]) ; <-- this is obviously wrong

; is there a way to read "directly" the element [2] of the nested array from $Array[3] ?

thanks

 

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

  • Moderators

Pincopanco,

Not as far as I know - you have to extract it into a temporary variable first. Basically, how is Autoit to know that the outer array element is actually another array? ;)

M23

Edit: See below for a solution using the Beta - I forgot all about that. :>

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I do the same as Melba said, save to variable first, then access the array using the temporary variable. There is no way to do it directly.

Dim $AnotherArray[5] = ["zero", "one", "two", "three", "four"]
Dim $Array[4]
Dim $Temp

$Array[0] = 1
$Array[1] = True
$Array[2] = "Text"
$Array[3] = $AnotherArray

ConsoleWrite($Array[3][2]) ; <-- this is obviously wrong

$Temp = $Array[3] ;Grab the array and save to $Temp

ConsoleWrite($Temp[2] & @CRLF)  ;Prints 2 to the console

; is there a way to read "directly" the element [2] of the nested array from $Array[3] ?

Posted the code in case anyone else would like to follow along :)

Link to comment
Share on other sites

Thanks Melba23 and 0xdefea7 for the quick response

I was hoping that it was possible :(

I tried with _ArrayDisplay() .... it shows a "hole" in that position.....  :thumbsdown:

(also _ArrayDisplay() left me alone :P )

Edited by Pincopanco

 

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

This would kind of do what you want. I included an inputbox so you can see it can read the 2nd array from the first.

#include <array.au3>

Dim $AnotherArray[5] = ["zero", "one", "two", "three", "four"]
Dim $Array[4]

$input = InputBox("Enter number", "Enter number between 0 and 4")

$Array[0] = 1
$Array[1] = True
$Array[2] = "Text"
$Array[3] = $AnotherArray[$input]

_ArrayDisplay($Array)
Link to comment
Share on other sites

Hi Abberration

thanks for the reply, for a moment I believed in a solution ...
but in this way the $Array[3] element contains only one value and not the whole $AnotherArray
This is not an Array within an Array ;)
thanks again for trying

 

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

The beta offers a solution:

Local $a[2] = ["x", "y"]
Local $b[2] = [1, $a]
ConsoleWrite(($b[1])[0] & @LF)

Use it or wait for the release.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

You can do this with the AutoIt Beta.

 

Local $AnotherArray[5] = ["zero", "one", "two", "three", "four"]
Local $Array[4]

$Array[0] = 1
$Array[1] = True
$Array[2] = "Text"
$Array[3] = $AnotherArray

;~ ConsoleWrite($Array[3][2]) ; <-- this is obviously wrong
ConsoleWrite(($Array[3])[2] & @CR) ;<-- Works with AutoIt Beta v3.3.9.18
 
I don't know if you want to use the Beta version though.

Adam

Edit: jchd beat me to it.

Edited by AdamUL
Link to comment
Share on other sites

Thanks jchd & AdamUL

this is what I was looking for :)
I am using AutoIt 3.3.8.1
but I'm glad to know that the next version will allow this syntax.
thanks again to both

 

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

In addition you will be able to use indexing directly on the array returned by a function: ConsoleWrite("abc" & myfunc($param)[2] & @LF)

But of course you want to use such construct only when the probability is = 1 that myfunc returns a result incompatible with [2] index.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with 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...