Try IF kpLastValue <> kpValue THEN instead of IF kpLastValue != kpValue THEN, because the IF/then/else/Endif structure seems correct.

Cheers

Al.