Programming MSAgent am unable to trigger IdleStart

  • Thread starter Thread starter Dvanwig
  • Start date Start date
D

Dvanwig

Hello,
I have almost got a VB 2008 Express program working using MSAgent's Merlin
character. The character pops up and says a few words and then enters the
idle state. I can click a button on the form named btnQuit to exit the
program and that subroutine works. But I want to use the IdleStart event to
cause the program to terminate gracefully by itself if unattended. However,
my program never fires the IdleStart subroutine. Here's the coding. Can
someone tell me how to correct this program so that it will trigger the
IdleStart subroutine?

Public Class Form1
Public Merlin As AgentObjects.IAgentCtlCharacter
Public ctlAgent As New AgentObjects.Agent
Public Const DATAPATH = "C:\Windows\Msagent\Chars\Merlin.acs"

Private Sub frmMerlinForm_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ctlAgent.Connected = True
ctlAgent.Characters.Load("Merlin", DATAPATH)
Merlin = ctlAgent.Characters("Merlin")
Merlin.Show()
Merlin.Speak("Hello World")
End Sub

Private Sub Agent_IdleStart(ByVal Merlin As Object, ByVal e As
AxAgentObjects._AgentEvents_IdleStartEvent) Handles Agent.IdleStart
Merlin.Speak("Good Bye!")
End
End Sub

Private Sub btnQuit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnQuit.Click
End
End Sub
End Class
 
Dvanwig said:
Hello,
Can someone tell me how to
correct this program so that it will trigger the IdleStart subroutine?

Public Class Form1
Public Merlin As AgentObjects.IAgentCtlCharacter

I know nothing about MSAgents, but typically if you want to get an event, you
need to declare the object in question WithEvents, i.e.

Public WithEvents Merlin As AgentObjects.IAgentCtlCharacter
 
Thanks Steve...that might be part of the problem but I can't tell. Adding
"WithEvents" on the declartion line didn't make any difference so I don'
know. Maybe there's more to the WithEvent qualifier that I don't understand.
 
Dvanwig said:
Thanks Steve...that might be part of the problem but I can't tell.
Adding "WithEvents" on the declartion line didn't make any difference
so I don' know. Maybe there's more to the WithEvent qualifier that I
don't understand.

I just noticed this:

Private Sub Agent_IdleStart(ByVal Merlin As Object, ByVal e As
AxAgentObjects._AgentEvents_IdleStartEvent) Handles Agent.IdleStart
Merlin.Speak("Good Bye!")
End
End Sub

Handles Agent.IdleStart. Hmm, you have no object by the name of Agent.

I think you need to do

Public WithEvents ctlAgent As New AgentObjects.Agent

and then do

Private Sub Agent_IdleStart(ByVal Merlin As Object, ByVal e As
AxAgentObjects._AgentEvents_IdleStartEvent) Handles ctlAgent.IdleStart
Merlin.Speak("Good Bye!")
End
End Sub


Or just play around with it. You need to work out which object raises the event,
then declare that one WithEvents, then handle an event from that object. If it
is Merlin, then handle Merlin.IdleStart. Etc.
 
Thank you Steve,

Your suggestion solved the problem. It turns out it was ctlAgent that was
sending the StartIdle event and so I needed the "WithEvents" qualifier and a
new subroutine to refer to it. Then everything works fine. Thank you again
very much.

Dvanwig in Illinios
 
Back
Top