Mike, partly it is about dividing by zero, but also to test whether dx is +ve or -ve (see back end of the line below). I thought of testing
If dx=0 is false then
if max(dx,0) =0 is then...
but I thought this would be a common problem, and maybe I was ignorant of a more elegant and easy solution.
bear1=180-ATan(dy/dx)*rad2degree-90*(dx>0)+90*(dx<0)
regards, Peter