So, you have two programs that work, so you posted them, and you have some attempt to combine them that is somehow not doing what you want, that you need help with, but you didn't post that code or explain what the issues are. That's not how to move forward.