Tutorials    Freebies    Links    Feedback    Thank me
Agent Store   Agent Games   Legal notice    History
Home

Use Microsoft Agent in Visual Basic without adding the control to a form

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:

  1. On the Project menu, click References.
  2. Scroll down the list until you see "Microsoft Agent Control 2.0"
  3. Double-click "Microsoft Agent Control 2.0", so that a tick appears in the box next to it.
  4. Click OK.
  5. In the General | Declarations section of code on your start-up form, enter the following code:
    Dim WithEvents Agent1 As Agent
    Dim NowHide As Object
  6. In a module, enter this code:
    Dim Genie As IAgentCtlCharacter
  7. Add the following code to the 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")
  8. Now add this code:
    Private Sub Agent1_RequestComplete _
    (ByVal Request As Object)
    If Request Is NowHide Then Genie.Hide
    End Sub
Try this without "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.