Let me see if I have this right,
The first line of your Autoexec macro tells your application to quit if the function basSetEnvironment returns a value of 0, otherwise the macro continues with the startup. Correct?
Can you post your basSetEnvironment code? it sounds like that the problem amy lie in the function.