Jump to content

Variable variables


reecieboy
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...