Whenever I run my VB6 program and it crashes after I opened a COM port, the next time I try to run it from IDE, I get a busy COM port. I have to save my program and restart VB every time I get a bug in my program.

Is there a way to fix this or is there a way to add cleanup code to the VB IDE so that open COM ports are automatically closed when the program is ended?