just another thought on my last post. If you check the state of "magnetic_switch_closed" and jump into you're code where you increment your counter. Before you jump out and look for it being closed again, you should look for it to be open.

If not then you could count the same swith close multiple times all for the same instance.

something like:

Code:
if RB7pin10 = 1 then main ' make sure the switch opens before looking for another close
Else stay in loop...
Shane