Change the gosub to a goto, as it stands the gosub code will continue on return to the endif and code that follows it, not what you want I think.