Don't know what I changed, but the most important thing is that it works now. I also changed the order of the commands, because before the first hit of F7 would only display the current state and did not change anything, now it directly switches to the next language.

It would be better to set the "myLang" variable local for each buffer, because the spell option is also local. In case you use two or more buffers and activate "en_gb" for one, "g:myLang" contains 2 now if you want to activate it for another one, you have to press <F7> three times.

So change each occurrence of g:myLang to b:myLang and define it for each buffer when the function is called for the first time. For this: remove the "let g:myLang = 0" line and add the following statement to the function directly after the function declaration:

if !exists( "b:myLang" )
let b:myLang=0
endif

The spell option can be directly set to get(g:myLangList, b:myLang) (except for the case b:myLang==0, of course). This way, the list can be managed and accessed more easily: