Mbee Posted June 14, 2016 Share Posted June 14, 2016 OK, so I discovered from reading this: Arrays in Arrays that you can easily create and read from embedded arrays. Cool! To read the data stored in the embedded array, you enclose the left-hand side of the expression inside parentheses, as shown in the example from that tutorial (modified by myself for a test): Local $aContainerArray[2] Local $aInternalArray_0[2] = ["Internal-0-0","Internal-0-1"] Local $aInternalArray_1[2] = ["Internal-1-0","Internal-1-1"] $aContainerArray[0] = $aInternalArray_0 $aContainerArray[1] = $aInternalArray_1 Local $this = ($aContainerArray[0])[1] ConsoleWrite("1 element of InternalArray_0: " & $this & @CRLF) ConsoleWrite("0 element of InternalArray_1: " & ($aContainerArray[1])[0] & @CRLF) ConsoleWrite("0 element of InternalArray_0: " & ($aContainerArray[0])[1] & @CRLF) Note the "$this" assignment syntax with the parentheses. Now, all of that works fine, but what's the syntax for storing a new value into the embedded array? It seems to me it should be: ($aContainerArray[0])[1] = "Animal" Because it's the mirror image of the $this assignment. But it produces a syntax error! "error: Statement cannot be just an expression." So what's the correct syntax for storing data into an embedded array? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2016 Moderators Share Posted June 14, 2016 Mbee, I do not believe that you can store data in an embedded array, just read it. To change the content of an embedded array, you need to extract it, amend the content and then reinsert it in the outer array. M23 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...
Mbee Posted June 14, 2016 Author Share Posted June 14, 2016 My great thanks to you, @Melba23 ! You've saved me hours of head-bashing! I thought there were no Indirect operators native to AutoIt (though I imagine there are custom approaches, such as using DLLStructs or handles/pointers), but there one was with this parentheses business. But as you point out, it's one-way (read) only. I'm sure what you suggested as an alternative will work; it's just so... well, maybe not "ugly", but surely "inelegant". Thanks for the super-fast response! Link to comment Share on other sites More sharing options...
mikell Posted June 14, 2016 Share Posted June 14, 2016 ... So, as a general rule, try not to embed arrays within arrays unless you absolutely need to ... While 'need' is of course a very subjective concept, the phrase above can't be ignored Link to comment Share on other sites More sharing options...
Gianni Posted June 14, 2016 Share Posted June 14, 2016 (edited) a possible workaround....(?): #include <array.au3> Local $aContainerArray[2] Local $aInternalArray_0[2] = ["Internal-0-0", "Internal-0-1"] Local $aInternalArray_1[2] = ["Internal-1-0", "Internal-1-1"] $aContainerArray[0] = $aInternalArray_0 $aContainerArray[1] = $aInternalArray_1 Local $this = ($aContainerArray[0])[1] ConsoleWrite("1 element of InternalArray_0: " & $this & @CRLF) ConsoleWrite("0 element of InternalArray_1: " & ($aContainerArray[1])[0] & @CRLF) ConsoleWrite("0 element of InternalArray_0: " & ($aContainerArray[0])[1] & @CRLF) _ArrayDisplay($aContainerArray[0], 'Before') _SubArraySet($aContainerArray[0], 0, 'Animal') _ArrayDisplay($aContainerArray[0], 'After') Func _SubArraySet(ByRef $subarray, $iElement, $value) $subarray[$iElement] = $value EndFunc ;==>Test P.S, Since $subarray is passe ByRef it shouldn't be extracted, but accessed directly in the $aContainerArray...?? .. or not? Edited June 14, 2016 by Chimp Melba23 1 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 June 14, 2016 Moderators Share Posted June 14, 2016 Chimp, Interesting - I did not think that would work - but it obviously does. Good on you for finding out that it does. I think that the sub-array is indeed extracted "under the hood" - I seem to remember from a previous discussion that if arrays passed ByRef are modified then they are copied, altered and rewritten, which would explain why it works. M23 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...
AutoBert Posted June 14, 2016 Share Posted June 14, 2016 (edited) 2 hours ago, Melba23 said: I seem to remember from a previous discussion that if arrays passed ByRef are modified then they are copied, altered and rewritten Sorry, but the only argument to pass ByVal is to save the time and after reading: Quote The ByRef keyword indicates that the parameter should be treated as a reference to the original. By default the parameter is copied into a new variable but ByRef links the new variable to the original. Note that not only a named variable can be passed for a ByRef parameter - unnamed temporary variables, such as function return values, may be passed as ByRef parameters as well. However, a literal cannot be passed to a ByRef parameter. ByRef should be used when passing large amounts of data (such as the contents of a file) where copying all the data would impose a significant performance penalty. Another advantage is that passing a parameter ByRef when the function is intended to change the content of the parameter removes any requirement to Return the changed value as the original is directly affected. i hope AutoIt does this in same way as other programming languages. Edited June 14, 2016 by AutoBert Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 14, 2016 Moderators Share Posted June 14, 2016 AutoBert, Why are you sorry? Previous discussions with the Devs have explained that if an array is not passed ByRef, AutoIt will not make a copy unless the array content is altered within that function. As I stated above, I also seem to recall from another discussion that even if an array is passed ByRef then it will be actually copied, modified and rewritten if altered. To me that would make perfect sense as the internal core code would be very similar in the 2 cases. And as long as the ByRef case is transparent to the user, why should we care how it is dealt with "under the hood"? M23 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...
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