Humm i am not sure about your question.

But for what i could figured out you are traying to reconnect to a server when you have been disconnected and joines the proper channel etc etc etc.

Why you dont use the options that mirc have already.

Alt + o --> Connect --> Options --> "Reconnect on disconnection"
Note:. Dont forget to enable the connect retry out too

Them to join the channel you can use the "Channel list" icon the icon that you have on mirc.

With that you can choose to coonnect automatcaly when join a network ( choosed by you ).

Hope this can help.
If this was not what you ask for it, sorry...

good luck