Sign in to follow this  
Followers 0
tomagucci

Really Easy Array question

12 posts in this topic

#1 ·  Posted (edited)

hi, I am totally learning autoit from absolutely no computer programing background so please bear with me. Im trying to do something but I dont know to say it. here goes

$array[$i] = Random Value not zero

For $i=0 to $i=4 step + 1

Do

Generalcommand(); makes $array[$i] = 0

until $array[0] = 0 and $array[1] = 0 and $array[2] = 0 and $array[3] = 0 and $array[4] = 0

next

its the "$array[0] = 0 and $array[1] = 0 and $array[2] = 0 and $array[3] = 0 and $array[4] = 0" that I dont know how to shorten, if i just say $array[$i] = 0 it will stop whenever one of them turns to zero and it happens to be looping there, How do i say for all of them in one line without being so repetitive. I dont know how to address all of the array values at the same time.

Thanks for all the help, its greatly appreciated, been wracking my brain for hours

Chris

Edited by tomagucci

Share this post


Link to post
Share on other sites



you just need this.

For $i = 0 To 4
GeneralCommand()
Next
I don't see how you would need the do until statement unless your generalcommand() function changes the values of the array.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

it does, it changes them to zero, but i dont want it to stop doing it until all the values in the array have become zero. Does that make sense?,

sorry I saw where that was weird, does that help clairfy it?

Edited by tomagucci

Share this post


Link to post
Share on other sites

Then you still don't need the do until if it changes the element currently used. you could just mod the function to accept the current element/array as a parameter then pass it through the for/next loop.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

okay, the do is only the first part, here is the whole thing:

$array[$i] = Random Value not zero

For $i=0 to $i=4 step + 1

Do

Generalcommand(); makes $array[$i] = 0

until $array[0] = 0 and $array[1] = 0 and $array[2] = 0 and $array[3] = 0 and $array[4] = 0

If $array[0] = 0 and $array[1] = 0 and $array[2] = 0 and $array[3] = 0 and $array[4] = 0 then

exit

next

its more of the second part that isnt working, well technically it is, but the range of $i changes sometimes and if i need to edit i need to go back in and change everyone. the actual range of $i in my code is 12 and sometimes it will change to anywhere from 1-12

Edited by tomagucci

Share this post


Link to post
Share on other sites

because it doesnt stay constant like that, the values of $array are constantly changing, generalcommand() might change it to 0 once but it will change again, i need generalcommand() to keep working until every value is zero in one full loop

Share this post


Link to post
Share on other sites

You could try something like this to make it a bit easier (assuming you mod the generalcommand() to accept parameters).

For $i = 0 To UBound($array)
Generalcommand($array[$i])
$sum += $array[$i]
Next

If $sum = 0 Then
Exit
Endif

Share this post


Link to post
Share on other sites

generalcommand() modifies several things and $array[$i] cannot fit within the parameters. I really appreciate the help though

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

hmm well i tried it, I dont know how to modify the parameters to get that method to work. is there another method? isnt there something that can directly address the array? does += mean add them all together? if it does then thats all i need.

Edited by tomagucci

Share this post


Link to post
Share on other sites

yeah += means add the value of whatever is after the = to the variable on the left of the +, so -= would be minus, &= would append the data, etc.

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