AUTO / MAN mode best practices

Hello,

I am putting together a IRB 140 robot system with an indexing table.Everything is going to be controlled from a control panel, a PLC being master and the robot slave. There are two operating modes: AUTOMATIC and MANUAL (control panel switch).
Each of the two procedures (AUTO / MAN) works fine on its own, however I am having trouble coding them to work together.Specifically, I have tried putting them both in an IF ELSE statement based on the control panel switch, and everything enclosed in a WHILE TRUE loop.This approach is not satisfactory since control does not transfer right away between the two modes when I switch from one to the other, but rather happens after while (there are a lot of things happening in each mode).
I am not experienced in this kind of design and I would like to know if there are some sort of thumb rules for this(as I imagine most cells working auto and manual mode)…e.g should I run each mode in a trap routine instead of a regular procedure?

Thanks
Alex

Can you post some of your code?

Are you okay with losing your program pointer when someone switches modes or does it need to be retained?