I'll try 2 & 3...
Code:
For CounterA = 1 To 20 ; "CounterA" keeps track of the loop count for the first FOR/NEXT loop
For CounterB = 1 To 10 ; "CounterB" keeps track of the loop count for the second FOR/NEXT loop
Pause 1
Next CounterB
Pause 1
Next CounterA
What happens is...
The first loop begins (call it the "A" loop), and "CounterA" is automatically set to '1' at its start.
The next line of code starts up a second loop (the "B" loop), setting "CounterB" to '1' at the start of that loop.
Since the first "Next" command is the "Next CounterB" line of code, the "B" loop will now continue for 10 iterations until it is finished.
We now hit the "Next CounterA" line - we go back to the beginning of "A" loop, the "CounterA" variable is incremented by 1, and then we restart the "B" loop again, finishing it before again going back to the "A" loop.
The "B" loop runs start to finish each time through the "A" loop. The "B" loop will be run a total of 20 times, for a total of 200 cycles (10 cycles per "B" loop, times 20 "A" loops).
While a FOR/NEXT loop is running, you want to make sure your code does not alter the "Counter" variable that is used to store the loop count (unless you are intentionaly changing it!).
Before a FOR/NEXT loop starts, or once the loop is finished, the variable can be used freely for other purposes in your code.
On #3... Give the variables names that mean something to you - instead of x, y, z, etc, use RedLED, GreenLED (pin variables), EventCount, PumpStatus, etc. Try not to use abbreviations, as you'll forget what they mean after a short time (I always do anyways).
Clear as mud? :-)
Arch
Last edited by Archilochus; - 1st October 2006 at 17:04.
"Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"
Bookmarks