muzle6074 Posted January 17, 2009 Share Posted January 17, 2009 Hi all, Long time no scripting, how can I declare a dynamic array in au3? By this I mean an array that I can just keep re-adding values to without changing the size of the array. Regards muzle6074 Link to comment Share on other sites More sharing options...
Developers Jos Posted January 17, 2009 Developers Share Posted January 17, 2009 To my knowledge dynamic arrays are array that can be resized but that doiesn't happen automatically. You either declare an Array that is large enough to hold all instances or you redim the array when you need more. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Armand Posted January 17, 2009 Share Posted January 17, 2009 @muzle6074 if you want to add something to the array you have to change it's size but it doesn't mean it can't be dynamically done. #include <Array.au3> Dim $yourAr For $i = 0 To 5 $retNew = InputBox("Extend array", "Add something new to this array:") If IsArray($yourAr) = 1 Then $Bound = UBound($yourAr) ReDim $yourAr[$Bound+1] $yourAr[$Bound] = $retNew Else Dim $yourAr[1] $yourAr[0] = $retNew EndIf Next _ArrayDisplay($yourAr) (E)Njoy Dlund 1 [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2009 Moderators Share Posted January 17, 2009 muzle6074,To the best of my knowledge, AutoIt arrays are inherently dynamic in the sense that the values within a declared array can be updated any time you wish to any value you require without problem, and without affecting the number of elements.From the Help file:Data types in ArraysIt 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]=$AnotherArrayThis has not been strictly forbidden in AutoIt. However, it is NOT ADVISABLE to mix different datatypes in an Array. If you do need to change the number of elements, Dim or ReDim are the functions to use - the latter preserves existing values within surviving elements. Additionally, the include file Array.au3 contains a whole bunch of interesting functions to add and delete elements from within code, but the functions tend to be quite slow if used within loops because of the ReDim calls that they use.M23 GoogleGonnaSaveUs 1 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...
muzle6074 Posted January 17, 2009 Author Share Posted January 17, 2009 Thank you all for your input! Link to comment Share on other sites More sharing options...
BugFix Posted January 17, 2009 Share Posted January 17, 2009 Another way: use array alternatives (object) like i.e. System.Collections.ArrayList or Scripting.Dictionary.So you can increase/decrease your array object without ReDim.Here an example:$ObjList = ObjCreate("System.Collections.ArrayList") ; create $ObjList.Add($VALUE) ; add value $VALUE = $ObjList.Item($Index) ; get value $ObjList.Remove($VALUE) ; delete by name $ObjList.RemoveAt($Index) ; delete by index $Array = $ObjList.ToArray ; list to array ; and more... $oDICT = ObjCreate('Scripting.Dictionary') $oDICT.Add($KEY, $VALUE) ; add pair (key/value) $VALUE = $oDICT.Item($KEY) ; get value $oDICT.Item($KEY) = $VALUE ; set value $oDICT.Remove($KEY) ; delete key $oDICT.RemoveAll ; delete all keys ; and more... genius257, BPCM and Keith_Greenberg 3 Best Regards BugFix Link to comment Share on other sites More sharing options...
nazikus Posted August 19, 2014 Share Posted August 19, 2014 Great. ArrayList is so much easier to use. But any idea how to call static methods like IndexOf() ? Another way: use array alternatives (object) like i.e. System.Collections.ArrayList or Scripting.Dictionary. So you can increase/decrease your array object without ReDim. Here an example: $ObjList = ObjCreate("System.Collections.ArrayList") ; create $ObjList.Add($VALUE) ; add value $VALUE = $ObjList.Item($Index) ; get value $ObjList.Remove($VALUE) ; delete by name $ObjList.RemoveAt($Index) ; delete by index $Array = $ObjList.ToArray ; list to array ; and more... $oDICT = ObjCreate('Scripting.Dictionary') $oDICT.Add($KEY, $VALUE) ; add pair (key/value) $VALUE = $oDICT.Item($KEY) ; get value $oDICT.Item($KEY) = $VALUE ; set value $oDICT.Remove($KEY) ; delete key $oDICT.RemoveAll ; delete all keys ; and more... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 19, 2014 Moderators Share Posted August 19, 2014 nazikus,Welcome to the AutoIt forums. In future, please do not necro-post in threads this old - that functionality has already been incorporated into AutoIt. Look for the Map datatype in the latest Beta versions. 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