Right, after days of staring at my code, it finally occurred to me where I had gone wrong. I had set a variable in the array which I was then using the same variable to write to the registry, which was not right. After changing the variable name, it all works.

Thank God thats over !