Hi Chris
The VB under Mach is a little... well let's say idiosyncratic
I suspect you are falling foul of the caveat in the UG because you are indeed effectively calling a script from within a script. The finer workings of Mach are of course only known to the inner sanctum of Art (retired) & Brian et al (not sure if there actually is an "et al" or whether its just poor Brian on his tod these days
)
So... You run your script. This is running in a separate thread to Mach. Your script sets #123 to 1 and then makes a "code" call to Mach - effectively requesting Mach to run mysub1.tap - Mach will do this in it's own good time. Meanwhile your script whips round the loop, sets #123 to 2 and requests Mach to run mysub2.tap which again, it will do when it's good and ready. Meanwhile your code whips round - sees i%=2 and jumps to the line after the next which is the end of your script - it closes down the thread.
Back to Mach - Mach looks on it's "VB request pending buffer" (my made up name for this bit of Mach) which I'm guessing is a stack (LIFO (last in first out)) rather than a queue (FIFO (first in first out)) and hence runs mysub2.tap. Of course by this time 123 is 2. That done it pops the next request from the stack - mysub1.tap and of course #123 is still 2.
FWIW you could try putting a "while isMoving() wend" construct after the call to "code". This will cause your loop to wait on a sync semaphore from the Mach thread before continuing. A reason why this may not work is that while your code is waiting, Mach will run your mysubX.tap. IF the VB interpreter is non-reentrant then it's still going to fail (which may be why there is the caveat in the UG).
This of course may be quite wrong - but it's my best guess.
Cheers
Ian