Jump to content
Sign in to follow this  
reecieboy

Variable variables

Recommended Posts

reecieboy

Are "variable variables" possible...

I believe thats what they're called

Local $var = "Product"
Local $num = 1 ;GUICtrlRead($Product_Number)
if StringIsAlNum($num) Then
   $var & $num = "Info"
   MsgBox(0, "", $Product1)
EndIf

a variable is set from the value of both $var and $num creating $Product1

I appreciate any help on this matter as it would help me use alot less code in my current project.

Thanks in advance

Edited by reecieboy

Share this post


Link to post
Share on other sites
Shaggi

Through string manipulation... Ie. Eval(), Assign(), Execute() etc.

Local $var = "Product"
Local $num = 1 ;GUICtrlRead($Product_Number)
if StringIsAlNum($num) Then
   Assign($Var & $Num, "Info")
   MsgBox(0, "", $Product1)
EndIf

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites
AdmiralAlkex

You can do that with Assign(), but that's rarely a good solution. Instead, look at using array(s) to store the data. There's a Array tutorial in the wiki that may be of your interest.

Share this post


Link to post
Share on other sites
reecieboy

Thanks to both. My intention is that i have multiple gui controls with similar handles

for example

$Product1

$Product2

$Product3

so on an so forth..

so i really need to GUICtrlRead($var & $num) if you know what i mean, I forsee that not being possible with Assign

Share this post


Link to post
Share on other sites
Shaggi

Thanks to both. My intention is that i have multiple gui controls with similar handles

for example

$Product1

$Product2

$Product3

so on an so forth..

so i really need to GUICtrlRead($var & $num) if you know what i mean, I forsee that not being possible with Assign

GuiCtrlRead(Eval($Var & $Num))

There ya go.

Edited by Shaggi

Ever wanted to call functions in another process? ProcessCall UDFConsole stuff: Console UDFC Preprocessor for AutoIt OMG

Share this post


Link to post
Share on other sites
reecieboy

Thank you very much shaggi, really do appreciate your time..

Share this post


Link to post
Share on other sites
hannes08

As AdmiralAlkex already stated, it would be a better idea to use arrays here:

Dim $array[6]
$array[0] = 5
For $i = 1 To $array[0]
    $array[$i] = GuiCtrlCreateInput("...")
Next
 
;and later on:
 
For $i = 1 To $array[0]
    GuiCtrlRead($array[$i])
Next

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
czardas

On a side note, which may be of interest. With AutoIt, many operations will convert a number to a string automatically, and vice versa. For example the use of the operator &= will concatenate two numbers and return a string. It makes a lot of coding easier, but it can be confusing sometimes. The functions Number() and String() are sometimes needed to alter the variable type.

Edited by czardas

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  

×