Arion Posted November 22, 2010 Share Posted November 22, 2010 I have been trying to get my application to work with arrays, yet it seems like most of the functions that work with arrays either require numeric indices, or the help pages are so vague as to be almost useless. Am I right, is AutoIt not equipped to deal with string indices properly or am I just reading everything wrong? [quote]“Programming is like *ex: one mistake and you’re providing support for a lifetime.”(Michael Sinz)[/quote] [quote]“There are two ways to write error-free programs; only the third one works.”(Alan J. Perlis)[/quote] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2010 Moderators Share Posted November 22, 2010 Arion,As far as I know you need numeric indices in arrays. Could you give an example of a "string" index which does not work? It might be as simple as using Number to convert it to the correct type. 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...
czardas Posted November 22, 2010 Share Posted November 22, 2010 I don't think you can replace the index numbers, but you can use a two dimensional array and use column 0 for a string type index. But you would have to include more code to get it to behave like an index (a kind of work around). That's if I understand you correctly. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Arion Posted November 22, 2010 Author Share Posted November 22, 2010 Arion, As far as I know you need numeric indices in arrays. Could you give an example of a "string" index which does not work? It might be as simple as using Number to convert it to the correct type. M23 To be honest, I put my other project on the back burner in order to write a registry UDF to make all this variable nonsense easier for people. As for the example: In my actual registry variable, I have the main var, and then secondary containers I call ACVs (Access Control Variables), which should be s string. Global $Registry[2] = [0, 'Registry'] Whereas registry should be the key, not the value (Yes, I know the way it is written it comes up as the value). I guess what I'm wondering is if there is a way to write it somewhat like in PHP: $arr[3] = ['key'=>'val', 'key1'=>'val1', 'key2'='val3'] [quote]“Programming is like *ex: one mistake and you’re providing support for a lifetime.”(Michael Sinz)[/quote] [quote]“There are two ways to write error-free programs; only the third one works.”(Alan J. Perlis)[/quote] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 22, 2010 Moderators Share Posted November 22, 2010 (edited) Arion, We have a terminology problem. The array you have posted is perfectly valid, but its parts are described thus: Index Element 0 0 1 "Registry" You can have strings as elements of arrays, but you need a numeric index to identfy the element - I trust that clears up your misconception. Now the Help file does suggest that you should not mix data types within an array - but I have never found that to be a problem, at least not with strings of shortish length such as the one you are using. Your other array would have to be written like this: $arr[3] = ["key'=>'val", "key1'=>'val1", "key2'='val3"] ; or $arr[3] = ['key"=>"val', 'key1"=>"val1', 'key2"="val3'] You need to use the "other" quote internally if you use one type to contain the string. I am afraid I do use PHP so I cannot comment on whether that is similar. Does that help? M23 Edit: Clarity - I hope! Further edit: "Should not" rather than "cannot" - see below. Edited November 23, 2010 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...
trancexx Posted November 22, 2010 Share Posted November 22, 2010 Associative array. Search now. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted November 22, 2010 Share Posted November 22, 2010 I agree with trancexx, sounds like you're talking about "Dictionary Object"/"Associative Array", something AutoIt doesn't do natively. Do a search with Titles Only set in the examples forum and you'll find some.Examples:I want to be a link too .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 Link to comment Share on other sites More sharing options...
James Posted November 22, 2010 Share Posted November 22, 2010 Yes, associative arrays. PHP uses the => operator to declare index names as indexes. AutoIt does not have them built in, Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
trancexx Posted November 22, 2010 Share Posted November 22, 2010 It wants to be a link... Twice I clicked. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
James Posted November 22, 2010 Share Posted November 22, 2010 It wants to be a link... Twice I clicked. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted November 22, 2010 Share Posted November 22, 2010 It wants to be a link... Twice I clicked. I laughed so hard my jaws hurt... A little.The new look on the links have great potentiality. .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 Link to comment Share on other sites More sharing options...
MvGulik Posted November 23, 2010 Share Posted November 23, 2010 (edited) Now the Help file does suggest that you cannot mix data types within an array where?Suggests against it, yes. Cannot, never seen that one. Edited November 23, 2010 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 23, 2010 Moderators Share Posted November 23, 2010 MvGulik, Earlier post amended. 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...
jvanegmond Posted November 23, 2010 Share Posted November 23, 2010 Local $arr[3][2] = [['key','val'], ['key1','val1'], ['key2','val3']] github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mat Posted November 23, 2010 Share Posted November 23, 2010 I have often thought of adding bits of code to AutoIt3Wrapper, as an additional pre process part. This was one of the things I thought of. Input: $myVar['string'] Output: $myVar[__getIndex('myVar', 'string')] It then adds code to the script... Or it could use the dictionary object. It would effectively add dictionary functionality to AutoIt. If you are only using one or maybe two, and you know their names then another solution is to have a function instead (in a similar way to how you would define a method for C# classes for using indexes): myVar('string') Func myVar($sString) Switch $sString Case ... EndSwtich EndFunc But that would mean "myVar('string') = 'test'" wouldn't work. And finally, there is the method I tend to use. Define indexes for a known dictionary as other variables: Global Const $x = 0 Global Const $y = 1 Local $aPos = MouseGetPos() MsgBox(0, "Test", "X: " & $aPos[$x] & @CRLF & "Y: " & $aPos[$y]) As you can see, it makes it very easy to see whats going on, and the great news is that it is so easy to do a find and replace at the end to get just the indexes, so you are not using any more memory... I've used that a lot, especially when making big programs with lots of global arrays storing stuff. Associative arrays as php knows them are not in AutoIt natively though. Maybe one day. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
trancexx Posted November 23, 2010 Share Posted November 23, 2010 This is piece of cake for AutoItObject. For example: #include "AutoItObject.au3" ; Initialize _AutoItObject_Startup() ; Create AutoIt-object Global $oArray = _AutoItObject_Create() ; Add properties For $i = 1 To 100 _AutoItObject_AddProperty($oArray, "key" & $i, $ELSCOPE_PUBLIC, "val" & $i) Next ; More _AutoItObject_AddProperty($oArray, "num", $ELSCOPE_PUBLIC, 123.456) _AutoItObject_AddProperty($oArray, "int", $ELSCOPE_PUBLIC, 7890) ConsoleWrite("key23 = " & $oArray.key23 & @CRLF) ConsoleWrite("num = " & $oArray.num & @CRLF) ConsoleWrite("int = " & $oArray.int & @CRLF) ConsoleWrite("key87 = " & $oArray.key87 & @CRLF) ; Set new val to key87 $oArray.key87 = "Nev value of key87" ConsoleWrite("key87 = " & $oArray.key87 & @CRLF) ; etc... ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Arion Posted November 23, 2010 Author Share Posted November 23, 2010 These are all good and well, but it merely skirts the fact that AutoIt is missing a very important piece of functionality, one which, in my opinion, should be fixed immediately. Until then though, I guess a workaround of a workaround will suffice. (And yes I was describing associative arrays, it's just been so long since I used PHP that I actually forgot what they were called>) [quote]“Programming is like *ex: one mistake and you’re providing support for a lifetime.”(Michael Sinz)[/quote] [quote]“There are two ways to write error-free programs; only the third one works.”(Alan J. Perlis)[/quote] Link to comment Share on other sites More sharing options...
Mat Posted November 23, 2010 Share Posted November 23, 2010 I don't like the use of the word "fixed". It's not a bug, or a problem with the language, it's something that's not implemented. Is there a particular reason you need associative arrays and none of the workarounds work? This is something that isn't really necessary in my opinion. php is something different, as it manages large webpages, often with different scripts doing different jobs that need to store globals etc. Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
MvGulik Posted November 23, 2010 Share Posted November 23, 2010 Or the word "immediately" for that matter. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
czardas Posted November 23, 2010 Share Posted November 23, 2010 (edited) I always thought associative arrays were just the same as normal arrays, with the addition of an alternative (string) index. Edited November 23, 2010 by czardas operator64 ArrayWorkshop 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