Ok after a lot of tries I finally have something that works. Here's the centre section of the code with the initialisation parts ommited for clarity

Code:
LED1 var  PORTB.4       'LED1 (green) on pin 10 (RB4)
LED2 var  PORTB.5       'LED1 (red) on pin 11 (RB5)

SW0 var PORTB.0          'switch input pin 6 (RB0)
SW1 var PORTB.1          'switch input pin 7 (RB1)

SWFLAG1 var Byte      ' counter for track 1

Swset1 var bit
Swset2 var bit

low led1
low led2 
               
Swset1=0 
Swset2=0
             
SWFLAG1=0

Main:

if SWFLAG1 >2 then     ' if the counter is >2 then reset all
    swset1=0
    swset2=0
    SWFLAG1=0
endif

If SW0=0 Then
swflag1 = swflag1 +1  ' increase count by 1
swset1=1
pause 500
endif

If SW1=0 Then 
swflag1 = swflag1 +1  'increase count by 1
swset2=1
pause 500
endif

if swset1=1 then
high led1                'then turn on RB4 (and hence the LED)
else
low led1                 'else, LED is off
endif

If Swset2=1 then       
high led2                'then turn on RB5 (and hence the LED)
else
low led2                 'else, LED is off
endif
Basically rather than try and compare a condition of swset1 and swset2 and SW0, I simply used SWFLAG1 as a counter to count the number of times the switches are activated, and if it is greater than 2 reset the couter and swset 1 and 2 to 0.

Now when sw0 goes low for the first time SWFLAG1 is = 1, when sw1 goes low SWFLAG1 =2 then when the loco is placed at the front of the train andis driven over SW0 for the second time SWFLAG1 =3. As the "IF SWFLAG1 > 2" condition is reached, SWFLAG1 is reset to 0, as is swset1 and swset2.

Now just have to replicate this for the other 6 inputs and outputs

I know this may seem trivial to the more experienced programmers, but its my first real program with PBP that is beyond the simple flash a LED, and I'm really pleased that I managed to figure something out, after some guidance from you guys here.

Thanks

Malcolm

Oh, and seeing that I RTFM and did my homework... do I qualify for a dozen lashes form Mel (alias Ms Whippy )