Sign in to follow this  
Followers 0
imacrazyballoono

Loop with variables

9 posts in this topic

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] )

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

How would I dim it?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How would I dim it?

dim $color[6]

You could also check the help file for 'dim'.

Edited by dirtymafia

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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] )

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

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