botanic Posted November 29, 2013 Share Posted November 29, 2013 is there any way i can access an array via its index name rather then a number I have the following array and $usersettings[1][1] works however $usersettings['vss'][1] does not [0]|10| [1]|vss|4 [2]|username| [3]|password| [4]|compress|6 [5]|limitbw|4 [6]|bwlimit| [7]|index|4 [8]|backuplength|30 [9]|systemstate|4 [10]|systemstatepath| Link to comment Share on other sites More sharing options...
orbs Posted November 29, 2013 Share Posted November 29, 2013 _ArraySearch() will give you the index of the element where a string is found. here's a small example: #include <Array.au3> Dim $a[4][2] $a[3][0]='vss' $a[3][1]=4 ; the rest of the array is empty MsgBox(0,'',$a[_ArraySearch($a,'vss')][1]) Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
hannes08 Posted November 29, 2013 Share Posted November 29, 2013 What you are looking for are associative arrays.Check the UDF by Nutster: '?do=embed' frameborder='0' data-embedContent>> Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
kylomas Posted November 29, 2013 Share Posted November 29, 2013 botanic, When I want to refer to an array index by some name instead of offset I do it like this... #include <array.au3> local enum $vss = 1, $username, $password, $compress, $limitbw, $bwlimit, $index, $backuplength, $systemstate, $systemstatepath local $array[10] = [10] $array[$username] = 'some user name' $array[$password] = 'some password' $array[$systemstate] = 'FUBAR' _arraydisplay($array) The drawback to this technique is that the ENUM defs have to be kept in sync with the array (if you expand or contract the array at some point). I've never used the UDF pointed to by hannes08. It may eliminate this problem. One other alternative is to use the dictionary object. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 kylomas,One way of keeping the Enums and the array in sync is to do this (taken from one of my scripts):Local Enum $eStart, $eReset, $eRepeat, $eReload, $eFile, $eRecent, $eZone, $eRepeat_Option_State, $eZone_Option_State, _ $eFolder_Name, $eFolder_Alias, $eFolder_Data_File, $eMax Local $aParam_List[$eMax]Now the array will always have the correct number of elements - and if you want a count in [0] it is easy to arrange. 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...
kylomas Posted November 30, 2013 Share Posted November 30, 2013 @M23 - Thanks... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Inververs Posted November 30, 2013 Share Posted November 30, 2013 * all and you do not know what in the beta already have unofficial support for associative arrays? Local $table[] $table['vss'] = 'hello)' ConsoleWrite($table['vss'] & @LF) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 Inververs,That functionality is not complete or stable, will certainly not be supported by any of the AutoIt team and is completely undocumented as to its proper use - plus it could be removed at any time. I strongly suggest that people do NOT start using it until such time as it is formally announced as at least an "Experimental" item - perhaps in an eventual 3.3.11.## Beta. 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...
Inververs Posted November 30, 2013 Share Posted November 30, 2013 well, let's hope that this feature will make part Autoit. tnx 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