Follow these instructions to be able to use Microsoft Agent in Visual Basic without adding the control to a form. The code given will make Genie appear, say "Hi", then disappear:
General | Declarations section of code on your start-up form, enter the following code:
Dim WithEvents Agent1 As Agent
Dim NowHide As Object
Dim Genie As IAgentCtlCharacter
Form_Load() event of your start-up form:
Set Agent1 = CreateObject("Agent.Control.2")
Agent1.Connected = True
Agent1.Characters.Load "Genie", "genie.acs"
Set Genie = Agent1.Characters("Genie")
Genie.Show
Set NowHide = Genie.Speak("Hi")
Private Sub Agent1_RequestComplete _
(ByVal Request As Object)
If Request Is NowHide Then Genie.Hide
End Sub
WithEvents" in the line: Dim WithEvents Agent1 As Agent" to see why it is needed.
I hope you have enjoyed this tutorial. Please use the feedback form to send any comments about it to me.
If you would like to show your appreciation and support for The Agent LaunchPad, see the Thank me page.