Thanks for that Paul.
I tried your suggestions and the results were the same.
There seems to be an anomaly with the operation of the flaps which seems to be at the root of the issue.
As I described in my post above, after setting the flaps manually the code (whichever version) operates as required if it is the first flight after starting FSX. Any subsequent flights and the flaps don't retract if they have been set manually.
As a test, I set up two buttons to set and retract the flaps with the code:
The results of testing with the buttons:
After starting FSX:
I set the flaps manually and click on the flaps up button and the flaps retract.
I set the flaps manually again, click on the flaps up button and the flaps don't retract.
With the flaps still set down, I click on the flaps down button, then clicking on the flaps up button the flaps retract.
This behaviour is mirrored when the program runs, for the first flight OK but subsequent flights only work if the flaps are set with the button before takeoff and not manually.
For what it's worth the landing gear operation works every time.
At the moment I'm experimenting with the above code using a modified version of your FSUIPCClientExample_VB and the above code is in the Sub Timer1_Tick.
Cheers
Paul