see the attachment file please!
Go to Solution.
I haven't looked at that horrible flowchart but rather followed the description in the text above, corrected your routine and provided also one with a slightly different approach.
View solution in original post
thank you very much for helping me to solve the problem