Sign in to follow this  
Followers 0
Hypermind

"Variable variables" (ex. $student_$studentnumber)

5 posts in this topic

Hello,

I'm new to autoit and i was wondering how to 'merge' variables.

For instance (weird example I know):

$xpos = 5
$ypos = 2
$cell+$xpos+_+$ypos = "message"
MsgBox(0, "title", $cell5_2)

In php one can do it like this (combining $a and $i):

${a.$i}

Is this possible in autoit?

Thanks in advance :unsure:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In php one can do it like this (combining $a and $i):

${a.$i}

Do you mean $a="lorem" and $i="ipsum"... and after combining them you get $a="loremipsum"?

$a="lorem"
$i="ipsum"
$a &= $i
Msgbox(0,"","Variable $a is: " & $a)

Take a look to Language Operators

Edited by sahsanu

Share this post


Link to post
Share on other sites

all apologies if i misunderstood, but in case you wanted to assign multiple variables to something else entirely...

$xpos = 5
$ypos = 2

IF Assign("cell" & $xpos & "_"& $ypos , "message" , 2) Then MsgBox(0, "title", eval("cell" & $xpos & "_"& $ypos))

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@sahsanu

No I'm sorry that is not what I mean.

It's difficult for me to explain.. I found a solution on php.net (for php) but it shows a solution for my problem.

Maybe this will clear things up

To generate a family of variables, such as $a1, $a2, $a3, etc., one can use "variable variables" as follows:

<?php

for ($i = 1; $i <= 5; $i++) {

${a.$i} = "value";

}

echo "$a1, $a2, $a3, $a4, $a5";

//Output is value, value, value, value, value

?>

Note that the correct syntax is ${a.$i} rather than the perhaps more intuitive $a{$i}

The dot (.) is the string concatenation operator.

A family of variables might be used as an alternative to arrays.

So I want to do that with AutoIt, however, this is really all that I need to know:
${a.$i} = "value"
but then ofcourse in AutoIt language if that's possible.

@iamtheky

Hmm maybe that will work.. im a newbie so im really bad with autoIt and i don't understand your code completely but i will take a look at it, thanks for your reply.

Edited by Hypermind

Share this post


Link to post
Share on other sites

@sahsanu

No I'm sorry that is not what I mean.

Ah apologies, then iamtheky gave to you the right info. :unsure:

Another example:

For $i=1 To 5
    Assign("a" & $i, $i)
Next
MsgBox(0,"",Eval("a1") & Eval("a2") & Eval("a3") & Eval("a4") & Eval("a5"))

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