Sign in to follow this  
Followers 0
exodius

Incremental variables help

4 posts in this topic

I have a number of variables that are all named by the same naming scheme ($Hours1, Hours2, etc. ) and what I want to do is be able to do a loop statement that will sequentially go through them, something like:

$Hours1 = 1
$Hours2 = 2

$x = 1
Do
MsgBox ( 0, "", $Hours & $x )
$x = $x + 1
Until $x = 3

But it doesn't work because $Hours is a new variable. Is there a way to get this to work?

Share this post


Link to post
Share on other sites



try declaring hours?


AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

I have a number of variables that are all named by the same naming scheme ($Hours1, Hours2, etc. ) and what I want to do is be able to do a loop statement that will sequentially go through them, something like:

$Hours1 = 1
$Hours2 = 2

$x = 1
Do
MsgBox ( 0, "", $Hours & $x )
$x = $x + 1
Until $x = 3

But it doesn't work because $Hours is a new variable. Is there a way to get this to work?

The best way I've found to do this is to make the Hours variable an Array rather than Scalar values, then loop the array. I've tried dynamic variable assignments using numeric assignments as you are looking for and could necer get it to work. Try this instead:

Dim $hour
; create an Array $Hours with 3 elements, and assign a value to the elements
; note - there are also other ways to create the array here. see split in the help.
Dim $Hours[3] = [1, 2, 3]

; etc...

; either solution depending on what you want to do


; method 1 if you intend to call all items from a loop
For $hour IN $Hours
    MsgBox ( 0, "", $hour)
Next

; method 2 if you intend to call items directly or from a limited loop
For $i = 0 To UBound($Hours)-1
    MsgBox ( 0, "", $Hours[$i])
    Next

HTH

billmez

Share this post


Link to post
Share on other sites

The best way I've found to do this is to make the Hours variable an Array rather than Scalar values, then loop the array. I've tried dynamic variable assignments using numeric assignments as you are looking for and could necer get it to work. Try this instead:

Dim $hour
; create an Array $Hours with 3 elements, and assign a value to the elements
; note - there are also other ways to create the array here. see split in the help.
Dim $Hours[3] = [1, 2, 3]

; etc...

; either solution depending on what you want to do
; method 1 if you intend to call all items from a loop
For $hour IN $Hours
    MsgBox ( 0, "", $hour)
Next

; method 2 if you intend to call items directly or from a limited loop
For $i = 0 To UBound($Hours)-1
    MsgBox ( 0, "", $Hours[$i])
    Next

HTH

billmez

thnx

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