Jump to content

Loop with variables


Recommended Posts

Can I a loop that is something like this? Look at line 6, I want the variable to be one more each time it goes through the loop. I.E. first time variable would be $color[1]. Second would be $color[2] and so on.

$time = 1
do
    $mult = $time * 2
    $num = $time * 10
    $left = 958 - $num
    $color[$time] = $mult
    $time = $time + 1
until $time = 5

MsgBox( 0, "", $color[1] )
MsgBox( 0, "", $color[2] )
MsgBox( 0, "", $color[3] )
Link to comment
Share on other sites

  • Developers

Can I a loop that is something like this? Look at line 6, I want the variable to be one more each time it goes through the loop. I.E. first time variable would be $color[1]. Second would be $color[2] and so on.

$time = 1
do
    $mult = $time * 2
    $num = $time * 10
    $left = 958 - $num
    $color[$time] = $mult
    $time = $time + 1
until $time = 5

MsgBox( 0, "", $color[1] )
MsgBox( 0, "", $color[2] )
MsgBox( 0, "", $color[3] )
Yes you can after you have Dim(ed) the array... Dim $Color[6]

I would use a "For $time = 1 to 5 ... Next" loop, but this should also work

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

How would I dim it?

It is in my answer.... and try also to open the help file and read about suggestions made before posting a reply. :D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I read the documentation on dim, it is very confusing. Can someone show me how it works?

dim basically initiates a variable.

You can do the same with normal variable by doing this: $variable = ""

You need to use Dim in the case of an array to make it useable as an array.

When you do dim $color[6] you are getting the ability to store in $color[0] $color[1] $color[2] and so on up to 5. Keep in mind you use 0 first not 1.

I'm not the best at explaining but maybe that will help give you a 50000 ft. view

Link to comment
Share on other sites

it helped a lot thanks. So I would just put dim $color[6] at the top and then it would work? so like this:

dim $color[6]
$time = 1

do
    $mult = $time * 2
    $num = $time * 10
    $left = 958 - $num
    $color[$time] = $mult
    $time = $time + 1
until $time = 5

MsgBox( 0, "", $color[1] )
MsgBox( 0, "", $color[2] )
MsgBox( 0, "", $color[3] )
Link to comment
Share on other sites

it helped a lot thanks. So I would just put dim $color[6] at the top and then it would work? so like this:

dim $color[6]
$time = 1

do
    $mult = $time * 2
    $num = $time * 10
    $left = 958 - $num
    $color[$time] = $mult
    $time = $time + 1
until $time = 5

MsgBox( 0, "", $color[1] )
MsgBox( 0, "", $color[2] )
MsgBox( 0, "", $color[3] )
try it..should work

Also if you use a For next it will automatically incrememt your $time like this

dim $color[6]
dim $time

For $time = 1 to 5
    $mult = $time * 2
    $num = $time * 10
    $left = 958 - $num
    $color[$time] = $mult
    msgbox(0,"",$color[$time])
Next
Edited by dirtymafia
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...