Gianni Posted August 22, 2013 Share Posted August 22, 2013 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 22, 2013 Moderators Share Posted August 22, 2013 (edited) 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? M23Edit: See below for a solution using the Beta - I forgot all about that. Edited August 22, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
0xdefea7 Posted August 22, 2013 Share Posted August 22, 2013 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 More sharing options...
Gianni Posted August 22, 2013 Author Share Posted August 22, 2013 (edited) 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..... (also _ArrayDisplay() left me alone ) Edited August 22, 2013 by Pincopanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
abberration Posted August 22, 2013 Share Posted August 22, 2013 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) Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
Gianni Posted August 22, 2013 Author Share Posted August 22, 2013 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jchd Posted August 22, 2013 Share Posted August 22, 2013 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
AdamUL Posted August 22, 2013 Share Posted August 22, 2013 (edited) 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.AdamEdit: jchd beat me to it. Edited August 22, 2013 by AdamUL Link to comment Share on other sites More sharing options...
Gianni Posted August 22, 2013 Author Share Posted August 22, 2013 Thanks jchd & AdamUL this is what I was looking for I am using AutoIt 3.3.8.1but I'm glad to know that the next version will allow this syntax.thanks again to both Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jchd Posted August 22, 2013 Share Posted August 22, 2013 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now