put a stop

infact lots of them

throughout your code

and when run you can look at values in the code and the immediate window

the use of if else if is to polite CARP

too many else ifs

use the select instead

and put the halt/escape/kill process acion at the top to get out of it quicker

here to help ( but you must try )