For the case where x1=x2, the difference will be zero. You need to code this as a special case. Since you know the x-ordinate of both, there is no need to project... just work out the equivalent y-ordinate on the other line (checking first that its range will actually lead to an intersection... i.e. a1 < x1 and x1 < a2 for the case a1 < a2 )
You might also have to check for ((y2#-y1#)*(a2#-a1#) - (b2#-b1#)*(x2#-x1#)) = 0
You might also have to check for ((y2#-y1#)*(a2#-a1#) - (b2#-b1#)*(x2#-x1#)) = 0