Jump to content

Really Easy Array question


tomagucci
 Share

Recommended Posts

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
Link to comment
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.
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
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
Link to comment
Share on other sites

Link to comment
Share on other sites

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
Link to comment
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.

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...