Jump to content

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


Recommended Posts

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:

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

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

Link to comment
Share on other sites

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