Jochem Posted February 17, 2009 Share Posted February 17, 2009 I have the following problem; I want to create an variable based on some elements (string, and some text but it is not working: the variable I want to create = $Pic62g GUICtrlSetState($Pic62g, $GUI_HIDE) and i want to do it like this: GUICtrlSetState("$pic" & StringTrimRight(_ArrayToString($own, @TAB, 1, 1), 0, 0, 0, 1) ,4) & "g", $GUI_HIDE) the array to string is the name of computer WS-C62 I checked this with arraydisplay. how can this be done, or is this impossible Link to comment Share on other sites More sharing options...
Authenticity Posted February 17, 2009 Share Posted February 17, 2009 Sure, but why is the $pic is quoted? Link to comment Share on other sites More sharing options...
Manjish Posted February 17, 2009 Share Posted February 17, 2009 (edited) anything u put in a "" can never be a variable name.. So as far as i know u can't do something like this.. if there exists a method it seems out of my scope and knowledge.. Edited February 17, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
Jochem Posted February 17, 2009 Author Share Posted February 17, 2009 (edited) @Authenticity: because it is a part of the final variable $pic doesn't exists. Finally it has to become $Pic62g. The first part ($pic) is static and the last part is static (g) and the part in the middle has to be generated... Edited February 17, 2009 by Jochem Link to comment Share on other sites More sharing options...
Authenticity Posted February 17, 2009 Share Posted February 17, 2009 (edited) It's called Eval... try it like this: Dim $picWS_C62 = 'Text' MsgBox(0x40, 'Title', Eval('pic' & Return_picWS_C62())) Func Return_picWS_C62() Return 'WS_C62' EndFunc Edited February 17, 2009 by Authenticity Link to comment Share on other sites More sharing options...
JSThePatriot Posted February 17, 2009 Share Posted February 17, 2009 @Jochem The functionality you're looking for is available in AutoIt. I don't have an example right at the moment, but the help file does. Look up the Assign function. Regards, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Envoi Posted February 17, 2009 Share Posted February 17, 2009 (edited) @Authenticity: because it is a part of the final variable $pic doesn't exists. Finally it has to become $Pic62g. The first part ($pic) is static and the last part is static (g) and the part in the middle has to be generated... So, you almost need a function like VariableName = ("$pic" & StringTrimRight(_ArrayToString($own, @TAB, 1, 1), 0, 0, 0, 1) ,4) & "g") I don't know of a way to do that. But, what if you use an array? If the two characters between "$Pic" and "g" are always going to be numbers, you could use them as your array index. So: $n = StringTrimRight(_ArrayToString($own, @TAB, 1, 1), 0, 0, 0, 1) ,4) GUICtrlSetState($Pic_g[$n], $GUI_HIDE) Would something like that work? Edited February 17, 2009 by Envoi Link to comment Share on other sites More sharing options...
Envoi Posted February 17, 2009 Share Posted February 17, 2009 @Jochem The functionality you're looking for is available in AutoIt. I don't have an example right at the moment, but the help file does. Look up the Assign function. Regards, Jarvis But does this actually let you construct the variable name? The example shows: Global $variable If Assign("variable", "Hello") Then MsgBox(4096, "", $variable) ; Will print "Hello" But $variable is already declared. I don't think his $Pic62g can be declared until he finds the "62." Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2009 Moderators Share Posted February 17, 2009 Jochem,This will do what you want:$Pic62g = "This is what I want!" Global $array[2] = [0, "WS-C62"] $res1 = _ArrayToString($array, @TAB, 1, 1) ConsoleWrite($res1 & @CRLF) $res2 = StringTrimLeft($res1, 4) ConsoleWrite($res2 & @CRLF) $res3 = "pic" & $res2 & "g" ConsoleWrite($res3 & @CRLF) MsgBox(0, "", Eval($res3)) ; And then you can put them all together! MsgBox(0, "", Eval("pic" & StringTrimLeft(_ArrayToString($array, @TAB, 1, 1), 4) & "g"))Good tip: when you want to use lots of embedded functions, break them out into single steps until you are sure you have each part right. You had parameter errors in the StringTrimLeft function (and you cannot tell your left from your right!).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...
Manjish Posted February 17, 2009 Share Posted February 17, 2009 gr8 job guys.. thanks for this topic jochem.. It has contributed positiely to my knowledge.. thanks M23, Authenticity.. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
JSThePatriot Posted February 17, 2009 Share Posted February 17, 2009 @Jochem Did you get what you needed? Thanks, Jarvis AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more) Link to comment Share on other sites More sharing options...
Jochem Posted February 18, 2009 Author Share Posted February 18, 2009 thanks to all, I indeed get what I wanted. After all I used the assign functions But after all it is not the best way to build my script I think, so I have to find another way to make it. 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