Before people start landing some very specific suggestions or requests to show code...
Clicking On The TaskBar:
Make sure you are running in Windowed Mode or it will delete all the textures in memory when the program is minimized or window focus is lost.
Merging Two Programs:
Double check the scope of all your variables. You very likely have things overlapping. This is very common.
Finding the Problem:
EXIT PROMPT Message String, Caption String
End
Use this to make your program terminate with a message. Keep working backward until you reach code that actually executes. Then test your variables there to find out what is going wrong. Then when the problem variable is found work back further in that direction.