Reputation: 15930
I want to enumerate a variable as so:
$x = 0
Do
$x+=1
$Day$x = True
Until $x = 7
The above returns a syntax error on $Day$x
(because it's only supposed to see one variable in the command). So basically, I want $Day1 = True
, $Day2 = True
, so on and so forth. Is there a way to accomplish this?
Upvotes: 0
Views: 1917
Reputation: 2360
Welcome to the wonderful world of arrays.
#include <Array.au3> ; for debugging
Global $Day[7]
$x = 0
Do
$Day[$x] = True
$x+=1
Until $x = 7
_ArrayDisplay($Day) ; For debugging
You can actually do what you originally described with $Day1, $Day2, $Day3 but it would be a very bad programming practice and I personally strongly discourage it. That being said, it is possible with the Assign function. You'd be using it for totally the wrong reason. But for completeness, here's how:
$x = 0
Do
Assign("Day" & $x, True)
$x+=1
Until $x = 7
MsgBox(0, "", $Day2)
Upvotes: 5