When I originally wrote the code to handle the “bye bye” command, I wanted Merlin to say “bye bye,” wave, then disappear before the program stopped. After I performed the Hide method, I inserted an Unload Me statement. Doing this caused the program to stop before Merlin had a chance to even begin speaking.
What was happening was that when the program finished, it dropped the connection to the Agent server, which immediately canceled all of the queued requests. So to handle this situation, I added the MyRequest object to the global declarations (see Listing 14.4, earlier in the chapter) and used it with the Hide request. I also needed to code the RequestComplete event, as shown in Listing 14.7. Then when the Hide method is finished, the RequestComplete event is fired, and the program ends properly.
Listing 14.7: Agent1_RequestComplete Event in Agent Demo
Private Sub Agent1_RequestComplete(ByVal Request As Object)
Unload Me
End Sub