disfated Posted February 13, 2011 Posted February 13, 2011 (edited) Simple piece of code, in which we want to store the element of array (which in turn is another array) in another variable: #Include <Array.au3> Global $arr[1][2] = [ [1, 2] ] Global $sub = $arr[0] _ArrayDisplay($sub) And we get Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Global $sub = $arr[0] Global $sub = ^ ERROR If we write #Include <Array.au3> Global $arr[1][2] = [ [1, 2] ] Global $sub[2] = $arr[0] _ArrayDisplay($sub) We get Missing subscript dimensions in "Dim" statement.: Global $sub[2] = $arr[0] Global $sub[2] = ^ ERROR So simple task, but I didn't find the way how I can do it. Have no idea. Please, help. offtopic, AutoIt has so horrible syntax when it comes to arrays. Why it doesn't use fully dynamic arrays (as it is in javascript for example)? Edited February 13, 2011 by disfated
Moderators Melba23 Posted February 13, 2011 Moderators Posted February 13, 2011 disfated, If you declare the array with 2 dimensions you need to use 2 dimensions to address its elements: #Include <Array.au3> ; Create internal array Global $aInternal_Array[3] = ["a", "b", "c"] ; Create wrapper array with internal array internally Global $arr[1][2] = [ [$aInternal_Array, 2] ] ; Extract internal array Global $sub = $arr[0][0] ; Note use of 2 dimensions to address element <<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Display internal array _ArrayDisplay($sub) Quote AutoIt has so horrible syntax when it comes to arrays.I do not find it that bad, but then I am used to it. 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: Reveal hidden contents 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
disfated Posted February 13, 2011 Author Posted February 13, 2011 (edited) Your code works fine. Thanks. BTW, it has the worse syntax that I could imagine. Ok, it's my problems One more question. Can I somehow do this Global $aInternal_Array[3] = ["a", "b", "c"] Global $arr[1][2] = [ [$aInternal_Array, 2] ] in one line? Edited February 13, 2011 by disfated
Moderators Melba23 Posted February 13, 2011 Moderators Posted February 13, 2011 (edited) disfated,No. If you want to use a variable as an array you have to declare it as such. AutoIt does not know (or care) what you put in an array as an element, but when you define the elements they must be single variable names, expressions or literal strings. Quote fully dynamic arraysCould you explain what exactly you mean by this - "dynamic" can mean different things to different people. Perhaps there is some way you can get AutoIt arrays to behave more to your taste. M23Edit: Added "expressions". Edited February 13, 2011 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: Reveal hidden contents 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
Bowmore Posted February 13, 2011 Posted February 13, 2011 (edited) Perhaps something like this would meet your needs. #Include <Array.au3> Global $arr[1][2] = [ [1, 2] ] Global $sub=_ArrayRow($arr,0) _ArrayDisplay($sub) Func _ArrayRow($array,$iRow) Local $aRow[UBound($array,2)] For $i = 0 To UBound($aRow) - 1 $aRow[$i] = $array[$iRow][$i] Next Return $aRow EndFunc Edited February 13, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
Tvern Posted February 13, 2011 Posted February 13, 2011 You can do it as one line, but it will still be two variable declarations. I don't think that's what you meant. #include <array.au3> Global $aInternal_Array[3] = ["a", "b", "c"], $arr[1][2] = [ [$aInternal_Array, 2] ] ;one line. _ArrayDisplay($aInternal_Array) _ArrayDisplay($arr) _ArrayDisplay($arr[0][0]) While I think the technical drawbacks are mostly fixed, most people still try to avoid storing arrays in other arrays, because you can't access the value's in the inner arrays directly and it can make code very confusing. If you know what you're doing it's fine, but I try to avoid it. I thought that maibe you where not aware of the ReDim keyword. it allows resizing of the arrays dimensions while keeping the existing content intact. (unless you make it smaller of coarse in which case some will go lost.) You can also change the number of dimensions the array has, but this will result in the array to be cleared. One thing to note is that ReDim is relatively slow, so if for instance you want to add 100 values to 100 rows, add 100 rows first, then add the values one by one, rather than adding 1 row and 1 value 100 times.
Moderators Melba23 Posted February 13, 2011 Moderators Posted February 13, 2011 Tvern, Quote You can do it as one line, but it will still be two variable declarations. I don't think that's what you meant.Excellent lateral thinking! 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: Reveal hidden contents 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
Tvern Posted February 13, 2011 Posted February 13, 2011 On 2/13/2011 at 1:28 PM, 'Melba23 said: Tvern,Excellent lateral thinking! M23The embarassing think is that I actually thought "of coarse you can do it in one line...". It was a little later that I realised he must have meant a single declaration.I have a tendacy to take people literally. (I had great fun in school explaining to teachers that my assignment was exactly what they asked for)
disfated Posted February 13, 2011 Author Posted February 13, 2011 (edited) On 2/13/2011 at 12:51 PM, 'Melba23 said: Could you explain what exactly you mean by this - "dynamic" can mean different things to different people. Perhaps there is some way you can get AutoIt arrays to behave more to your taste. I seems to me that my problem was that AutoIt doesn't handle multidimentional arrays as arrays of arrays, instead it handles them as a whole, like matrices. Am I right? "Fully dynamic" in js: arr = [] ; just some array, 0-elemens for now, i don't know what it will contain arr[5] = [1,1,1] ; auto-redim'ed to 6-elements, now contains subarray arr[5][2] = [ ['array', 'in', ['another', 'array']] ] ; "deepening" the array, using arrays as expressions without pre-declaration sub = arr[5][2][0] ; now sub contain link! to ['array', 'in', ['another', 'array']] sub[2] = 'not an array any more' ; changes in link ; cause changes in original object print(arr[5][2]) ; >> [ ['array', 'in', 'not an array any more'] ] arr = 'profit ))' On 2/13/2011 at 1:16 PM, 'Bowmore said: Perhaps something like this would meet your needs. Thanks, I got your idea. It's just coping the inner array. Though, I have to use 3-dim arrays, I think I would better use this terribly unefficient but handy solution, than will declare hundreds of unnecessary variables On 2/13/2011 at 1:19 PM, 'Tvern said: You can do it as one line, but it will still be two variable declarations. I don't think that's what you meant. You are right. That wasn't On 2/13/2011 at 1:19 PM, 'Tvern said: While I think the technical drawbacks are mostly fixed, most people still try to avoid storing arrays in other arrays, because you can't access the value's in the inner arrays directly and it can make code very confusing. If you know what you're doing it's fine, but I try to avoid it. I thought that maibe you where not aware of the ReDim keyword. it allows resizing of the arrays dimensions while keeping the existing content intact. (unless you make it smaller of coarse in which case some will go lost.) You can also change the number of dimensions the array has, but this will result in the array to be cleared. One thing to note is that ReDim is relatively slow, so if for instance you want to add 100 values to 100 rows, add 100 rows first, then add the values one by one, rather than adding 1 row and 1 value 100 times. Fortunately the dims of my data array are known in advance, but it has to be multi-dim and i need to get it's rows and pass them to another functions. I didn't think it is a problem for scriptable language of 2011 year )) I thought the main porpose of AutoIt is it's convinience and fast development... Hope that developers will discover user-friendly array operations in future versions... Thanks all very much!!! Edited February 13, 2011 by disfated
Moderators Melba23 Posted February 13, 2011 Moderators Posted February 13, 2011 disfated, Quote I seems to me that my problem was that AutoIt doesn't handle multidimentional arrays as arrays of arrays it handles them as a whole, like matrices. Am I right?Absolutely correct. An array element is a single item - even though it might well be another array. And you cannot extract a "sub-array" of elements from an array without using a function such as the one Bowmore suggested.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: Reveal hidden contents 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
disfated Posted February 13, 2011 Author Posted February 13, 2011 My brain could not even imagine that this might be so nowadays. Well, I'm just spoiled with javascript
AdmiralAlkex Posted February 13, 2011 Posted February 13, 2011 There is a Array tutorial in the wiki, you may want to take a look if there are still something you are unsure off. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
storme Posted February 14, 2011 Posted February 14, 2011 On 2/13/2011 at 2:18 PM, 'disfated said: My brain could not even imagine that this might be so nowadays. Well, I'm just spoiled with javascript G'day disfated What other languages have you tried? Every language has it's strengths and weaknesses AutoIT has a LOT more strengths than weaknesses or you wouldn't be here. Just a little comment I found while Google searching. -quote Arrays are one of Javascript's core data structures. However, arrays in Javascript are a totally different beast than arrays in most other languages. In Javascript arrays are a special case of objects. In fact they inherit from Object.prototype, which also explains why typeof([]) == "object". The keys of the object are positive integers and in addition the length property is always updated to contain the largest index + 1. This supports the second assumption (array == object). -/quote So maybe a comparison to other languages might be in order, maybe Javascript is the ODD one out. It would appear as if you should look into an "object" implementation of Arrays like JS uses. I'm sure you would be able to recreate the Arrays you are "familiar" with. Anyway.... you mentioned that you would have to create 100's of unnecessary array variables for your implementation. WHY? Why not just create a function that returns the sub array you want to add to the main array. Maybe you could start another thread explain what you want to do and see what the forum can suggest. Many times I've come here with ONE idea and come out with a totally different implementation because of great feedback. Just make sure you explain "what" you want to achieve not just what you are doing. Good Luck John Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E
disfated Posted February 15, 2011 Author Posted February 15, 2011 (edited) On 2/13/2011 at 3:06 PM, 'AdmiralAlkex said: There is a Array tutorial in the wiki, you may want to take a look if there are still something you are unsure off. Yes, of course i've read this before asking... On 2/14/2011 at 3:50 AM, 'storme said: G'day disfated What other languages have you tried? Every language has it's strengths and weaknesses AutoIT has a LOT more strengths than weaknesses or you wouldn't be here. I see that AutoIt has it's own power. I don't deny that. But it could be even more powerful. To my mind, one of the main goals of scriptable languages is rapid development and it mostly concerns AutoIt. One more miss - is absence of stuctures / objects (I do not mean OOP) in it. I think that many of programmers will be surprised not to see them at all. All script languages (which i can remember) I used - JS, ruby, php, even turbo pascal! (if my memory serves me), matlab - all treat m-dim arrays as arrays of arrays and all have some implementation of structs. On 2/14/2011 at 3:50 AM, 'storme said: Just a little comment I found while Google searching. -quote Arrays are one of Javascript's core data structures. However, arrays in Javascript are a totally different beast than arrays in most other languages. In Javascript arrays are a special case of objects. In fact they inherit from Object.prototype, which also explains why typeof([]) == "object". The keys of the object are positive integers and in addition the length property is always updated to contain the largest index + 1. This supports the second assumption (array == object). -/quote Don't mind that. Almost everything in JS is a "special case of objects" except a couple of primitives. On 2/14/2011 at 3:50 AM, 'storme said: Anyway.... you mentioned that you would have to create 100's of unnecessary array variables for your implementation. WHY? It's the array of initial const data. I've already managed this to work. I've flattened my array to 2 dimensions and used the function that was sugested earlier. I can't say I like that solution, but it works for now Now I need Thank you all for your participation. You are so friendly and helpful. This is what I love most about in AutoIt now. Edited February 15, 2011 by disfated
AdmiralAlkex Posted February 15, 2011 Posted February 15, 2011 On 2/15/2011 at 9:11 PM, 'disfated said: Yes, of course i've read this before asking...lol No newbie reads that thing, pretty much zero of them even finds the wiki!And what is wrong with our structs? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
disfated Posted February 15, 2011 Author Posted February 15, 2011 On 2/15/2011 at 9:42 PM, 'AdmiralAlkex said: And what is wrong with our structs?They are absent...I saw some trick with DllCreateStruct() and then DllSrtuctGet()/Set() or something like that. But this is totaly mess to my mind.Or I missed something?
willichan Posted February 15, 2011 Posted February 15, 2011 This is how I handle my My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash
disfated Posted February 17, 2011 Author Posted February 17, 2011 willichanI won't bear this _SetSubArray($a, _GetSubArray($a, 1, 2, 3) + 1, 1, 2 ,3)
willichan Posted February 17, 2011 Posted February 17, 2011 On 2/17/2011 at 8:17 PM, 'disfated said: I won't bear this I don't blame you. Dealing with sub-arrays is do-able, but it is messy. I'd avoid it where possible. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash
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