Chris is right, that is neater. But, it still won't work cos of the passing of variables from the main program to the sub- routine.
You need to change variable #1 and #3 to #101 and #103 (or whatever # as long as it aint #0 or anything between #1000 to #5999). Variables #100 to #999 will keep their values on a subroutine call. I beleive that's where your problem is- the conditional loop will never end 'cos the value in #1 is not getting passed from the main program to the sub- routine and so variable #1 is always zero on entering the sub- routine and hence your conditional WHILE is always TRUE.
Every time you call or return a subroutine the (local) #variable will be reset to zero UNLESS you G65 the variables prior to the start of the program which allows keeping their values (system variables). Even nested loops will reset the variable
at that level of sub- routine
My second suggestion in my previous post will work (ie: change the variables to above #99)... I think! but again, I'm not an expert.
I would definately use Chris's format for the equation- it's neater and simpler and intuitively right. Yours would probably work ok, but best to cover all the bases.
Please let us know if this works? If it does, you owe me a beer, lol: my mates down the pub at lunchtime were accusing me of being a workaholic as I scribbled over my notes with a pint of Stella
I'll try and find a link to Scott Martinez's excellent explanation of Macro Programming. It's incredibly good.