>I have mistake the select() function.
>I think that the select() funcion returns the highest opened wa.
It may, depending on the parameter you pass it. Check help for select(1) and select(0), they do have different meaning from select(). One of them should return the first unused, and the other the highest used workarea - but I actually never needed it, so I don't remember which is which. Don't trust me, therefore, better check the help.