Sign in to follow this  
Followers 0
Jochem

composing an variable with variables

12 posts in this topic

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

Share this post


Link to post
Share on other sites



Sure, but why is the $pic is quoted?

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Manjish

[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by Jochem

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Authenticity

Share this post


Link to post
Share on other sites

@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)

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Envoi

Share this post


Link to post
Share on other sites

@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."

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0