Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Programming MSAgent am unable to trigger IdleStart

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dvanwig - 09 Mar 2008 14:36 GMT
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
Steve Gerrard - 09 Mar 2008 16:41 GMT
> 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
Dvanwig - 09 Mar 2008 18:14 GMT
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.

> > Hello,
> > Can someone tell me how to
[quoted text clipped - 7 lines]
>
> Public WithEvents Merlin As AgentObjects.IAgentCtlCharacter
Steve Gerrard - 09 Mar 2008 20:05 GMT
> 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.
Dvanwig - 10 Mar 2008 03:18 GMT
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

> > 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
[quoted text clipped - 26 lines]
> then declare that one WithEvents, then handle an event from that object. If it
> is Merlin, then handle Merlin.IdleStart. Etc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.