frank10 Posted September 19, 2011 Share Posted September 19, 2011 I want to assign a dynamically array. I tried execute and eval with no luck: global $ioCucina = "A4" global $ioComandoA = StringSplit("11101001", "") Execute ("$ioComando" & StringLeft($ioCucina ,1) &"[" & Number(StringRight($ioCucina ,1)) & "] = x " ) or Eval ("$ioComando" & StringLeft($ioCucina ,1) &"[" & Number(StringRight($ioCucina ,1)) & "] = y " ) Msgbox(0,'',$ioComandoA[4]) ; still gives me "0" So how can I made that? Instead I can _read_ well with Execute: Execute ("$ioComando" & StringLeft($ioCucina ,1) &"[" & Number(StringRight($ioCucina ,1) & "]" ) btw: In the help file the example of Execute is without the $ sign. That works with normal var but not with array: they need the $. I think it should be noted in the help file. Link to comment Share on other sites More sharing options...
water Posted September 19, 2011 Share Posted September 19, 2011 I think function "eval" only evaluates the name of a variable but not an expression.According to the helpfile eval "Returns the value of the variable defined by an string" My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2011 Moderators Share Posted September 19, 2011 frank10, You need to assign the result of the Execute function like this - you had it as part of the value to be Executed: Global $ioCucina = "A4" Global $ioComandoA = StringSplit("11191001", "") $iExec = Execute("$ioComando" & StringLeft($ioCucina, 1) & "[" & Number(StringRight($ioCucina, 1)) & "]") MsgBox(0, '', "Direct: " & $ioComandoA[4] & @CRLF & "Execute: " & $iExec) I changed the value in the array to 9 to make sure we got the correct value. In the help file the example of Execute is without the $ signIn my Help file the example for Execute is: Local $a = 1 Local $v = Execute("$a+1") ; $v is set to 2 All $ signs present and correct - where do you see them missing? 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...
BrewManNH Posted September 19, 2011 Share Posted September 19, 2011 Eval doesn't work with arrays. Execute is used to read a value when the variable you're trying to read from can be an unknown name, decided by the expression you use in the function call, it doesn't assign values directly to variables, but can return the value to another variable. Here is a couple of ways of doing it, not very elegant, but it works.global $ioCucina = "A4" global $ioComandoA = StringSplit("11101001", "") If StringLeft($ioCucina, 1) = "A" Then $ioComandoA[StringRight($ioCucina, 1)] = "y" EndIf MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$ioComandoA' & @lf & @lf & 'Return:' & @lf & $ioComandoA[4]) ;### Debug MSGBOX ; or this way $ioComandoA = StringSplit("11101001", "") Switch StringLeft($ioCucina, 1) Case "a" $ioComandoA[StringRight($ioCucina, 1)] = "x" Case "b" ; do something else EndSwitch MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$ioComandoA' & @lf & @lf & 'Return:' & @lf & $ioComandoA[4]) ;### Debug MSGBOX If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Ramzes Posted September 19, 2011 Share Posted September 19, 2011 If you want, you can use DllStructCreate. Example: $Array = DllStructCreate("int array[10]") DllStructSetData($Array, 1, 110101, 3) MsgBox(32, "array[3]", DllStructGetData($Array, 1, 3)) Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
frank10 Posted September 19, 2011 Author Share Posted September 19, 2011 (edited) $iExec = Execute("$ioComando" & StringLeft($ioCucina, 1) & "[" & Number(StringRight($ioCucina, 1)) & "]") MsgBox(0, '', "Direct: " & $ioComandoA[4] & @CRLF & "Execute: " & $iExec) [/autoit] This is reading the array, and it works, but I wanted to write into it with Execute. In my Help file the example for Execute is: All $ signs present and correct - where do you see them missing? Yes, you're right, I was looking both Execute and Eval, and Eval is without $, but Execute has it... @BrewManNH Thank you, yes, I thougth of that, and it works even if the array name it's not really dinamically set, but anyway I think it's the only solution. @Ramzes DllStruct seems to accept Execute commands, but I can't get it fully right. More, it create an array you can't access normally... like this: MsgBox(0,'',$ArrayA[1]) DllStructSetData($ArrayA, 1, 01234,3) MsgBox(32, "arrayA[1]", DllStructGetData($ArrayA, 1,3)) Execute( "DllStructSetData(" & "$Array" & "A, 1, 9, 3)" ) MsgBox(32, "arrayA[1]", DllStructGetData($ArrayA, 1,3)) But if I want to set the n element in Array? If I change the element to numer >1 it gives me 0. Also with this: DllStructSetData($ArrayA, 1, 9) DllStructSetData($ArrayA, 2, 8) DllStructSetData($ArrayA, 3, 7) MsgBox(32, "arrayA[2]", DllStructGetData($ArrayA, 2)) it gives me 0. How can I set one digit in each element? I never used DllStruct before... Edited September 19, 2011 by frank10 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2011 Moderators Share Posted September 19, 2011 frank10,I wanted to write into it with ExecuteWhy? There must be an easier way than using a awful function like Execute. Can you provide a short working script which shows what you are really trying to do rather than the short snippet you provided in the OP. 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...
Ramzes Posted September 19, 2011 Share Posted September 19, 2011 (edited) Read help files. If you use array don't forget about index. DllStructSetData ( Struct, Element, value [, index ] ) DllStructSetData($ArrayA, 3, 7)change to DllStructSetData($ArrayA, 1, 7, 3)Little example:$MyArray = DllStructCreate("int age[5]; dword color[30]") DllStructSetData($MyArray, "age", 15, 0) DllStructSetData($MyArray, "age", 33, 1) DllStructSetData($MyArray, "age", 7, 2) ; DllStructSetData($MyArray, "age", x, n)... DllStructSetData($MyArray, "color", 565757, 0) DllStructSetData($MyArray, "color", 313355, 1) DllStructSetData($MyArray, "color", 183813, 2) ; DllStructSetData($MyArray, "color", x, n)... ; To get data use DllStructGetData($MyArray, name or numer of value, [element of array] ; age[2] $Age2 = DllStructGetData($MyArray, "age", 2) ; color[1] $Color1 = DllStructGetData($MyArray, "color", 1) MsgBox(32, "Example", "age[2]: " & $Age2 & @CR & "color[1]: " & $Color1 ) I hope it will help you. Edited September 19, 2011 by Ramzes Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
frank10 Posted September 19, 2011 Author Share Posted September 19, 2011 Well, it's really a very long script... But, the point is: I have some const like Const $ioSala = "A3" Const $ioCucina = "A4" .... Then at some point, I get two Strings like this "00110111", I called them A and B (but in the future I could get more) with each digit representing the status of one constant. When I want to change the status, I must invert that digit, but I must think in terms of "names", not position. So I want Cucina change the status corresponding to the 4° in the A string. I thougth of split the A string and access the 4° el, but with the constant name. This semplifies every change of the constant without worring to change the code every time it refers to Cucina: I need only to update the constant and all goes well. I could use String manipulation instead of array. But I thought I could use Execute in Array, instead it's no good for setting... Instead with string var I can make a StringReplace based on Constants. So I have two ways: the semi-dynamic way of BrewManNH with array or this StringReplace with strings. Link to comment Share on other sites More sharing options...
frank10 Posted September 19, 2011 Author Share Posted September 19, 2011 Thank you Ramzes, it works: $MyArrayA = DllStructCreate("int age[8]") DllStructSetData($MyArrayA, "age", 0, 0) DllStructSetData($MyArrayA, "age", 1, 1) DllStructSetData($MyArrayA, "age", 2, 2) DllStructSetData($MyArrayA, "age", 3, 3) DllStructSetData($MyArrayA, "age", 4, 4) MsgBox(32, "Example", "age[4]: " & DllStructGetData($MyArrayA, "age", 4) ) Execute( "DllStructSetData($MyArray" & StringLeft($ioCucina ,1)& ",'age', 9 ," & Number(StringRight($ioCucina ,1)) & ")" ) MsgBox(32, "Example", "age[4]: " & DllStructGetData($MyArrayA, "age", 4) ) I think this is the only method to fully-dynamically write an array. It remains the problem of accessing this array only with DllStruct. Anyway, now I have three possibilities. Thank you all. 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