Talk To Your Computer
Learn how to talk to your computer, and have it respond! You even have a nice little robot buddy to talk to!
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
<html>
<style fprolloverstyle>A:hover {color: #FF0000; font-weight: bold}
</style>
<top>
<center><H1><font color="#FF0000">Talking to your computer!</font></H1></center>
<center><H3><b><i>Learn how to speak to your computer with Microsoft Speech Recognition along with a character to talk to with Microsoft Agent!</i></b></H3></center>
<center><H4><b><i><a href="mailto:mTecnology@hotmail.com">By: Michael [MTGiga] Gerwitz</a></i></b></H4></center>
<center><H4><b><i><a href="http://welcome.to/mTecnology">mTecnology</a></i></b></H4></center>
<p><b>Anyone can talk to their computer! However, it just sits there like a rock not knowing you even said anything. If it does, then it sure as heck wouldn't understand you!</b></p>
<p><b>Microsoft has solved this problem. With one simple ActiveX control, we have the ability to talk to our computer. And with another simple control, we can add a professional character too!</b></p>
<body bgColor=&HCCCCC>
<ul>
<li>First, we need to download the <a href="http://activex.microsoft.com/activex/controls/agent2/actcnc.exe">Speech Recognition Engine (6 MB)</a></li>
<li>Download and install it using the link above
<li>Click <a href="http://www.microsoft.com/msagent/downloads.htm">HERE</a> for the download site. Click on the
Speech Control Panel button and download it.
<li>After it is installed, click on the first link in the index. Download and install it.
<li>Click on the link below it, and choose a character from the dropdown list. I like Robby the robot the most. There is also a bird (Peddy), and Genie, and Merlin.
You can use the others later. <u><i><b>If you do not choose Robby, things will
not make sense.</b></i></u><li>Then click on the download button to download the character. Install it, then continue with the next step.
<li>Now download the next two links, and install those. That will allow the computer to speak back to us. You should have clicked on every link but one.
</ul>
<p><b>So far, that should be easy. If you could not follow it, we clicked on every link in the contents at the top of the page except the bottom one. It may seem like we are ready, but we really aren't...</b></p>
<center><H2>Training</H2></center>
<p><b>If you try to speak to the computer now, it will have a very hard time "understanding" you. So, we need to train it.</b></p>
<ul>
<li>Enter the Control Panel. It can be found in the Start Menu.
<li>Find the Speech icon, and click on it. A dialog will open.
<li>Click on the "Other" tab at the top, the second one.
<li>Click on the "SAPI 4 Control Panel..." button to open yet another dialog.
<li>Click on the text in the list that reads "Microsoft Speech Recognition Engine 4.0 (English)" at the bottom.
<li>Click on the "Training..." button. Another dialog will open.
<li>NOTE: You may have done this already during the setup. It is wise to do it again, though.
<li>Choose a session from the list. None are too exciting...
<li>Click on the 'Next >' button to take you to the next screen.
<li>Get your microphone ready, because once you click on 'Next >' again, you will have to speak!
<li>It will ask you to read the story. Do NOT read abnormally! Read like you normally do so it learns how you speak.
<li>When you are done, it will update the computer. Keep doing it until you seem
comfortable. The more times you do it, the better it will get to know you!
</ul>
<p><b>Once that is done, you computer will better understand you. It takes a lot of work to get it good. Mine gets it correct about 90% of the time, but I still need work.</b></p>
<center><H2>Bringing It Together</H2></center>
<p><b>Now we are finally ready to start making our program. As I sit here typing this, I wonder exactly what this will do. Well, I now know, and you will know soon enough. Just follow all of the steps to get the final working program and be amazed at what Microsoft can do for us...</b></p>
<ul>
<li>Open Visual Basic and start a new Standard EXE project.
<li>Rename the form 'frmMain' and delete its caption property. The form will never be visible, so we do not need to worry about this.
<li>Set its Visible property to 'False' so we can not see it. We only want to see our little Agent.
<li>We now need to add the ActiveX controls to our project.
<li>Right-click on the toolbox and select 'Components'<li>In the list, find and
select <b>Microsoft Agent Control 2.0 </b>and <b>Microsoft Direct Speech
Recognition</b><li>You will see an ear and an agent appear in your toolbox.</ul>
<p><b>We now have everything we need added to our project. We can now start to
make it happen! We now must create a list of our commands to be loaded from a
text file.</b></p>
<p align="center"><font size="5"><b>Grammar</b></font></p>
<p align="left"><b>Open up Notepad. We must create our <i>own</i> file to load
the grammar and vocabulary from. It will only recognize what we enter in this
document. So, enter the following:</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0">[Grammer]<br>
type=cfg<br>
[<font color="#0000FF"><start></font>]<br>
<font color="#0000FF"><start></font>=<font color="#00FF00">Show Yourself </font>
</p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Hide Yourself</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Speak</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Execute Notepad</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Execute Microsoft Paint</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Execute Microsoft Visual Basic</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Display Character Map</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Disallow Commands</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Reallow Commands</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Hibernate</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Make Repairs</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Tell Me a Joke</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">What Is My Fortune</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Play Number Guessing Game</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Status Report</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">0</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">1</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">2</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">3</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">4</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">5</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">6</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">7</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">8</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">9</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">10</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Animate</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Display Animation List</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">Display System Information</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">System Shutdown</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
<start></font>=<font color="#00FF00">System Reboot</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>Save it in the same
directory as the project, naming it 'words.txt'. Now that our grammar list has
been created, we can load it into our program. We first need to place the
ActiveX controls onto our form.</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><font size="5"><b>
ActiveX Controls</b></font></p>
<p align="center" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>Drag the two new
controls onto the form (the ones that look like an agent and an ear). Name the
ear-like one 'Reco', for it will be our Speech Recognition Engine. Then, set its
'Visible' property to 'False'. Next, name the agent 'Agent', so all you have to
do is erase the one. This does not have a visible property.</b></p>
<p align="justify" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><font size="5"><b>Our
Agent</b></font></p>
<p align="center" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>Before we load the
list we just created, let's create our Agent object. You do not have to do it in
this order, but I just want you to see what our character will look like. Create
a new module and name it 'modMain'. Enter the following code in the General
Declarations section (at the top):</b></p>
<p align="justify" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="justify" style="margin-top: 0; margin-bottom: 0">
<font color="#0000FF">Public</font> Bot <font color="#0000FF">As</font>
IAgentCtlCharacterEx </p>
<p><b>This creates a new Agent character from an external source. Therefore, we
will have to load it. Double click on frmMain and enter the following code:</b></p>
<p style="margin-top: 0; margin-bottom: 0">Agent.Characters.Load "Robby",
"robby.acs"<br>
<font color="#0000FF">Set</font> Bot = Agent.Characters("Robby")<br>
Bot.Show<br>
<br>
Bot.Play "Wave"<br>
Bot.Speak "Hello!"<br>
Bot.Speak "How are you doing today?"<br>
<br>
Bot.MoveTo 200, 200</p>
<p><b>That is it! If you run the program now, you will see your robot wave to
you, speak, then move. Let's take a look at the code.</b></p>
<p><b>The first two lines load the bot. The 'robby.acs' is the file we load it
from. The third line shows our bot. The Bot.Play "Wave" line will play his
'Wave' animation. We will take a look at animating much more in the future.
Then, we tell the bot to speak with Bot.Speak. Finally, the MoveTo command will
move the bot to a different part of the screen.</b></p>
<p><b>Before you move on, try to do some different things with it. Modify what
it says when it appears, move it to a different position on the screen.</b></p>
<p align="center"><b><font size="5">Loading the Grammer</font></b></p>
<p align="justify"><b>We can not speak to the computer until we load the list we
just created. Enter the following code above all the code we just put in the
Form_Load procedure:</b></p>
<p align="justify">Reco.GrammarFromFile App.Path & "\Words.txt"<br>
Reco.Activate</p>
<p><b>To see if it loaded correctly, we will make a simple example. If you speak
a phrase we created, it will output it to the debug window. Please note that it
may not recognize you every time. Only speak what is in our list. Double-click
on Reco and enter this in its Phrase_Finish procedure:</b></p>
<p><font color="#0000FF">Debug</font>.<font color="#0000FF">Print </font>Phrase</p>
<p><b>As you speak, look in the Debug Window. If it outputs any of the phrases
listed in Words.txt, we can continue.</b></p>
<p align="center"><font size="5"><b>Responding</b></font></p>
<p align="justify"><b>How do we respond to this? Well, we need to replace the
one line of code we just entered with a little more:</b></p>
<p align="justify"><font color="#0000FF">On Local Error Resume Next</font><br>
<font color="#0000FF">Debug</font>.<font color="#0000FF">Print </font>Phrase<br>
<br>
<font color="#0000FF">Select Case</font> Phrase<br>
<font color="#0000FF">Case</font> "Show Yourself"<br>
Bot.Show<br>
<br>
<font color="#0000FF">Case</font> "Hide Yourself"<br>
Bot.Hide<br>
<br>
<font color="#0000FF">End Select</font></p>
<p><b>Please note that it <i>is</i> case sensitive, so you must type it <i>
exactly</i> as it appears above. All we do is output the phrase said to the
Debug Window, then check it. These two phrases are the basic ones, they show and
hide the bot. If it is 'Show Yourself', then the bot will be displayed. If it is
'Hide Yourself', we will hide the bot. It is that simple. Try it out and see if
it works for you. Please be patient, it may take a while to recognize...</b></p>
<p align="center"><font size="5"><b>Speaking</b></font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>We will now program
our bot to speak to us. Please modify the above code so it looks like this:</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">On
Local Error Resume Next</font><br>
<font color="#0000FF">Debug</font>.<font color="#0000FF">Print </font>Phrase<br>
<br>
<font color="#0000FF">Select Case</font> Phrase<br>
<font color="#0000FF">Case</font> "Show Yourself"<br>
Bot.Show<br>
<br>
<font color="#0000FF">Case</font> "Hide Yourself"<br>
Bot.Hide<br>
</p>
<p align="left" style="margin-top: 0; margin-bottom: 0">
<font color="#0000FF">Case</font> "Speak"</p>
<p align="left" style="margin-top: 0; margin-bottom: 0">
BotSpeak</p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><br>
<font color="#0000FF">End Select</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>In the above code, we
only added two lines. It will call a sub procedure which will randomly choose
something for our bot to say. In modMain, create a new sub procedure named
'BotSpeak':</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
Public Sub</font> BotSpeak()</p>
<p align="left" style="margin-top: 0; margin-bottom: 0">
Randomize</p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><br>
<font color="#0000FF">Dim</font> r <font color="#0000FF">As
Integer</font><br>
r = Int(16 * Rnd)<br>
<br>
<font color="#0000FF">Select Case</font> r<br>
<font color="#0000FF">Case</font> 0<br>
Bot.Speak "I
love you!"<br>
<br>
<font color="#0000FF">Case</font> 1<br>
Bot.Speak
"You are amazing!"<br>
<br>
<font color="#0000FF">Case</font> 2<br>
Bot.Speak
"Make me a sandwich!"<br>
<br>
<font color="#0000FF">Case</font> 3<br>
Bot.Speak
"I'm tired..."<br>
<br>
<font color="#0000FF">Case</font> 4<br>
Bot.Speak
"Hello!"<br>
<br>
<font color="#0000FF">Case</font> 5<br>
Bot.Speak
"Dreams do come true!"<br>
<br>
<font color="#0000FF">Case</font> 6<br>
Bot.Speak
"Solve the equation 8(2x + 3) - (5x + 3x + 4)"<br>
<br>
<font color="#0000FF">Case</font> 7<br>
Bot.Speak
"What is the meaning of life?"<br>
<br>
<font color="#0000FF">Case</font> 8<br>
Bot.Speak "I
hate you, go away!"<br>
<br>
<font color="#0000FF">Case</font> 9<br>
Bot.Speak
"Make me!"<br>
<br>
<font color="#0000FF">Case</font> 10<br>
Bot.Speak
"I'm so happy being with you!"<br>
<br>
<font color="#0000FF">Case</font> 11<br>
Bot.Speak
"Have you read the book 844454XC50?"<br>
<br>
<font color="#0000FF">Case</font> 12<br>
Bot.Speak "I
want some self time..."<br>
<br>
<font color="#0000FF">Case</font> 13<br>
Bot.Speak
"Humans are obsolete!"<br>
<br>
<font color="#0000FF">Case</font> 14<br>
Bot.Speak "I
can not wait to take over your world!"<br>
<br>
<font color="#0000FF">Case</font> 15<br>
Bot.Speak
"South Park rules!"<br>
<br>
<font color="#0000FF"> End Select<br>
End Sub</font></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>You should be able to
understand that. We first choose a random number. Then, we tell the bot to speak
the text accociated to that number. That is it! Run the program, say "Speak",
and see what it says. Feel free to change the text to whatever you'd like.</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="center" style="margin-top: 0; margin-bottom: 0"><font size="5"><b>
Executing Applications</b></font></p>
<p align="center" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>This is a very easy
topic to cover. All you have to do is add the following code to what we
currently have in the Phrase_Finish procedure:</b></p>
<p align="left" style="margin-top: 0; margin-bottom: 0"> </p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">
Case</font> "Execute Notepad"<br>
Shell "C:\Windows\NOTEPAD.exe", vbNormalFocus<br>
<br>
<font color="#0000FF">Case</font> "Execute Microsoft Paint"<br>
Shell "C:\WINDOWS\SYSTEM32\mspaint.exe", vbNormalFocus<br>
<br>
<font color="#0000FF">Case</font> "Execute Microsoft Visual Basic"<br>
Shell "C:\Program Files\Microsoft Visual
Studio\VB98\VB6.exe", vbNormalFocus<br>
<br>
<font color="#0000FF">Case</font> "Display Character Map"<br>
Shell "C:\WINDOWS\SYSTEM32\charmap.exe", vbNormalFocus</p>
<p><b>The 'Shell' command will execute an EXE file. The first parmeter is the
Path, where the executable is located. The second is the focus. Do you want it
to have the focus, do you want it to be minimized, maximized, or normal?</b></p>
<p align="center"><font size="5"><b>Disallow and Reallow</b></font></p>
<p align="left"><b>Before we get started, add a public Boolean variable named
'Disallow'. Now, add the following code at the top of the Phrase_Finish
procedure:</b></p>
<p align="left"><font color="#0000FF">If</font> Phrase = "Reallow Commands"
<font color="#0000FF">And</font> Disallow <font color="#0000FF">Then</font><br>
Bot.Play "DoMagic1"<br>
Bot.Play "DoMagic2"<br>
<br>
Bot.Play "Idle1_1"<br>
Disallow = <font color="#0000FF">False</font><br>
Bot.Speak "Welcome back!"<br>
<font color="#0000FF">End If</font><br>
<br>
<font color="#0000FF">If </font>Phrase = "Disallow Commands"
<font color="#0000FF">Then</font><br>
Bot.Play "DoMagic1"<br>
Bot.Play "DoMagic2"<br>
<br>
Disallow = <font color="#0000FF">True</font><br>
Bot.Play "Idle1_1"<br>
Bot.Speak "I will wait for your return!"<br>
<font color="#0000FF">Exit Sub</font><br>
<font color="#0000FF">End If</font></p>
<p align="left"><font color="#0000FF">If</font> Disallow <font color="#0000FF">
Then Exit Sub</font></p>
<p align="left"><b>Run the program and say 'Disallow Commands'. Now, try to get
it to speak. You can't. Now say 'Reallow Commands'. It can speak again! This is
good if you don't want someone messing around with your bot.</b></p>
<p align="center"><font size="5"><b>Hibernating and Making Repairs</b></font></p>
<p align="left"><b>These are only two animations. Hibernating will, of course,
but it to sleep. Make Repairs will make him take off his head, and make repairs.
Add the following code:</b></p>
<p align="left"><font color="#0000FF">Case </font>"Make Repairs"<br>
Bot.Play "Idle2_2"<br>
<br>
<font color="#0000FF">Case</font> "Hibernate"<br>
Bot.Play "Idle3_2" </p>
<p><b>You should understand that tiny amount of code. These two animations can
also be played if you leave your bot alone long enough.</b></p>
<p align="center"><font size="5"><b>Jokes</b></font></p>
<p align="left"><b>This is the same concept as speaking. You can just copy the
BotSpeak procedure and replace the lines with jokes. I will give you two. You
can come up with some of your own. Enter the following code in the Phrase_Finish
procedure:</b></p>
<p align="left"><font color="#0000FF">Case</font> "Tell Me a Joke"<br>
TellJoke</p>
<p align="left"><b>Now, create the sub procedure in modMain:</b></p>
<p align="left"><font color="#0000FF">Public</font> <font color="#0000FF">Sub</font>
TellJoke()<br>
<font color="#0000FF">Dim</font> r <font color="#0000FF">As
Integer</font><br>
r = Int(2 * Rnd)<br>
<br>
Bot.Play "GetAttention"<br>
<br>
<font color="#0000FF">Select Case</font> r<br>
<font color="#0000FF">Case</font> 0<br>
Bot.Speak
"Why didn't the chicken cross the road?"<br>
Bot.Speak
"Because he was chicken!"<br>
<br>
<font color="#0000FF">Case</font> 1<br>
Bot.Speak
"Why didn't the man cross the road?"<br>
Bot.Speak
"Because he didn't want to!"<br>
Bot.Play
"Confused"<br>
<br>
<font color="#0000FF">End Select</font><br>
<br>
Bot.Play "GetAttentionReturn"<br>
<font color="#0000FF">End Sub</font></p>
<p align="left"><b>Say "Tell Me a Joke" and listen. If you have any good jokes
that are <i>yours</i> (I have millions of them, but they are not mine. That is
why they are not on here), feel free to <a href="mailto:mTecnology@hotmail.com">
send them to me</a>!</b></p>
<p align="center"><b><font size="5">Fortune Telling</font></b></p>
<p align="left"><b>Again, this is very similar to joke telling and speaking.
Enter the following lines in the Phrase_Finish procedure:</b></p>
<p align="left"><font color="#0000FF">Case</font> "What Is My Fortune"<br>
TellFortune</p>
<p><b>Now, create the procedure in modMain:</b></p>
<p><font color="#0000FF">Public Sub</font> TellFortune()<br>
<font color="#0000FF">Dim</font> r <font color="#0000FF">As
Integer</font><br>
r = Int(14 * Rnd)<br>
<br>
Bot.Play "Process"<br>
<br>
<font color="#0000FF">Select Case</font> r<br>
<font color="#0000FF">Case</font> 0<br>
Bot.Speak "Do
not go outside tomorrow..."<br>
<br>
<font color="#0000FF">Case</font> 1<br>
Bot.Speak
"Keep looking behind your back!"<br>
<br>
<font color="#0000FF">Case</font> 2<br>
Bot.Speak "In
the sky is your answer!"<br>
<br>
<font color="#0000FF">Case</font> 3<br>
Bot.Speak
"ERROR - DEATH TOO SOON!"<br>
<br>
<font color="#0000FF">Case</font> 4<br>
Bot.Speak
"Hold on to your belongings..."<br>
<br>
<font color="#0000FF">Case</font> 5<br>
Bot.Speak "I
see great things in your future!"<br>
<br>
<font color="#0000FF">Case</font> 6<br>
Bot.Speak "Do
NOT answer the door!"<br>
<br>
<font color="#0000FF">Case</font> 7<br>
Bot.Speak
"tomorrow will be a great day for you!"<br>
<br>
<font color="#0000FF">Case </font>8<br>
Bot.Speak "It
says - 'NEXT BIRTHDAY'"<br>
<br>
<font color="#0000FF">Case</font> 9<br>
Bot.Speak
"I'd rather not say!"<br>
Bot.MoveTo
10, 10<br>
<br>
<font color="#0000FF">Case</font> 10<br>
Bot.Speak
"Take shelter!"<br>
Bot.Hide<br>
<br>
<font color="#0000FF">Case</font> 11<br>
Bot.Speak
"You will be married tomorrow!"<br>
<br>
<font color="#0000FF">Case</font> 12<br>
Bot.Speak
"You are dead, I'm afraid..."<br>
Bot.Think "Ha
ha ha ha ha!"<br>
<br>
<font color="#0000FF">Case</font> 13<br>
Bot.Speak
"ERROR - MISPRINT"<br>
<br>
<font color="#0000FF"> End Select<br>
End Sub</font></p>
<p><b>There is something new up there. Bot.Think. Instead of speaking, the agent
displays a cloud with the text in it. The rest we have already gone through.</b></p>
<p align="center"><font size="5"><b>Number Guessing Game</b></font></p>
<p align="left"><b>This is a tiny bit more involved. First create a Boolean
variable in modMain called InGame, and an Integer variable named GuessNum. Now,
put this at the top of the Phrase_Finish sub:</b></p>
<p align="left"><font color="#0000FF">If </font>InGame <font color="#0000FF">
Then</font><br>
GameInput Phrase<br>
<font color="#0000FF">Exit Sub</font><br>
<font color="#0000FF">End If</font></p>
<p align="left"><b>Now, add this to the same procedure:</b></p>
<p align="left"><font color="#0000FF">Case</font> "Play Number Guessing Game"<br>
PlayGame</p>
<p align="left"><b>We have two procedures to create. Let's start with PlayGame:</b></p>
<p align="left"><font color="#0000FF">Public Sub</font> PlayGame()<br>
GuessNum = Int(11 * Rnd)<br>
<br>
Bot.Play "Explain"<br>
Bot.Speak "You have three tries to guess the number I am
thinking of."<br>
Bot.Speak "I will tell you if you are too high or too low..."<br>
<br>
Bot.Play "Process"<br>
Bot.Speak "I am thinking of a number between 0 and 10..."<br>
<br>
InGame = <font color="#0000FF">True</font><br>
<font color="#0000FF">End Sub</font></p>
<p align="left"><b>This procedure explains what you are to do, and chooses a
number. It then sets the InGame variable to 'True' allowing us to bypass all
other commands and worry only about the numbers we are guessing:</b></p>
<p align="left">Public Sub GameInput(Phrase As String)<br>
<font color="#0000FF">If </font>Phrase = "0"
<font color="#0000FF">Or</font> Phrase = "1" <font color="#0000FF">Or </font>
Phrase = "2" <font color="#0000FF">Or</font> Phrase = "3"<font color="#0000FF">
Or </font>Phrase = "4" <font color="#0000FF">Or</font> Phrase = "5"<font color="#0000FF">
Or</font> Phrase = "6" <font color="#0000FF">Or</font> Phrase = "7"
<font color="#0000FF">Or</font> Phrase = "8" <font color="#0000FF">Or</font>
Phrase = "9" <font color="#0000FF">Or</font> Phrase = "10" <font color="#0000FF">
Then</font><br>
<br>
<font color="#0000FF">Dim</font>
tmpNum <font color="#0000FF">As Integer</font><br>
<font color="#0000FF">Static</font>
GNum <font color="#0000FF">As Integer</font><br>
<br>
<font color="#0000FF"> If</font> GNum
= 3 <font color="#0000FF">Then</font> GNum = 0<br>
tmpNum = Int(Phrase)<br>
<br>
<font color="#0000FF"> If</font>
tmpNum > GuessNum <font color="#0000FF">Then</font><br>
Bot.Speak
<font color="#0000FF">CStr</font>(tmpNum) & " - Number too high"<br>
<br>
<font color="#0000FF"> ElseIf</font>
tmpNum < GuessNum <font color="#0000FF">Then</font><br>
Bot.Speak
<font color="#0000FF">CStr</font>(tmpNum) & " - Number too low"<br>
<br>
<font color="#0000FF">ElseIf</font>
tmpNum = GuessNum <font color="#0000FF">Then</font><br>
Bot.Play
"Congratulate"<br>
Bot.Speak
<font color="#0000FF">CStr</font>(tmpNum) & " - That is correct!"<br>
<font color="#0000FF">If </font>GNum = 0 <font color="#0000FF">Then</font>
Bot.Speak "WOW! First Try!"<br>
<br>
InGame =
<font color="#0000FF">False</font><br>
<font color="#0000FF"> Exit Sub<br>
End If</font><br>
<br>
GNum = GNum + 1<br>
<br>
<font color="#0000FF">If</font> GNum
= 3 <font color="#0000FF">Then</font><br>
Bot.Play
"Sad"<br>
Bot.Speak
"You did not get it..."<br>
Bot.Speak
"The correct number was " & <font color="#0000FF">CStr</font>(GuessNum) & "..."<br>
<br>
InGame =
<font color="#0000FF">False</font><br>
<font color="#0000FF"> End If<br>
End If<br>
End Sub</font></p>
<p align="left"><b>This is really some simple code. I simplified the first line
so it is easier to understand. We check to see if what the user said is actually
a number. If it is, we continue. If not, we bypass it. Then, we reset the tries
count (GNum). Then, we change the string into an integer and store it in tmpNum.
The bot will then inform us if it is too high or too low. If we are correct or
take our three turns, the game is over.</b></p>
<p align="center"><font size="5"><b>Status Report</b></font></p>
<p align="left"><b>This is nothing good. I just added this because every robot
must have status reports. It is also here if you decide to turn your robot into
a pet like a tamagotchi (I did). Every time, the bot will say he is operating a
optimum efficiency:</b></p>
<p align="left"><font color="#0000FF">Case</font> "Status Report"<br>
Bot.Play "Explain"<br>
Bot.Speak "I am operating at optimum efficiency!"</p>
<p align="center"><b><font size="5">Animation</font></b></p>
<p align="left"><b>If you've looked at Microsoft Word or any of the Office
products, you can animate the agents. Yes, they <i>are</i> agents, so keep this
in mind: YOU CAN USE THEM IN YOUR APPS!</b></p>
<p align="left"><b>First, we are going to create the Animation List. Follow
these simple steps:</b></p>
<ul>
<li>
<p align="left"><b>Create a new form and name it frmAni</b></li>
<li>
<p align="left"><b>Add a ListBox control to it, naming it lstAni</b></li>
<li>
<p align="left"><b>Add three CommandButtons: cmdPlay, cmdStop, and cmdCancel</b></li>
<li>
<p align="left"><b>In cmdStop, add this line of code: </b>Bot.Stop</li>
<li>
<p align="left"><b>In cmdCancel, add this line: </b>Unload Me</li>
</ul>
<p align="left"><b>There, now we have the form set up. Make sure Option Explicit
is not at the top of the code for the form, then double-click on it and add the
following code to the Form_Load procedure:</b></p>
<p align="left"><font color="#0000FF">For Each</font> AnimationName<font color="#0000FF">
In </font>Bot.AnimationNames<br>
lstAni.AddItem AnimationName<br>
<font color="#0000FF">Next</font></p>
<p align="left"><b>This will loop through all the animations and add them to our
list. You will see this soon. Add this to cmdPlay's code:</b></p>
<p align="left"> <font color="#0000FF">On Error GoTo</font>
ErrOut<br>
Bot.Stop<br>
Bot.Play lstAni.Text<br>
<font color="#0000FF">Exit Sub</font><br>
<br>
ErrOut:<br>
Bot.Speak "ERROR - UNABLE TO PLAY"</p>
<p><b>This will play the currently selected animation in the list. If there is
an error, our bot will tell us.</b></p>
<p><b>Now, we need to add the code for 'Auto Animation' when the user says
'Animate'. It will choose one from the list, play it, and never show the form.
Add a public Boolean variable named SelfAni in the General Declarations section
of the form, and add the following code below the other in the Form_Load
procedure:</b></p>
<p><font color="#0000FF">If</font> SelfAni <font color="#0000FF">Then</font><br>
<font color="#0000FF">Dim</font> r <font color="#0000FF">As
Integer</font><br>
r = Int(lstAni.ListCount * Rnd)<br>
lstAni.ListIndex = r<br>
Bot.Stop<br>
Bot.Play lstAni.Text<br>
<font color="#0000FF"> Unload Me</font><br>
<br>
<font color="#0000FF">End If</font></p>
<p><b>If SelfAni is true, then it will not display the form and choose a random
animation. You will see how we will do this momentarily, so add the following
code in the Phrase_Finish procedure:</b></p>
<p style="margin-top: 0; margin-bottom: 0"><font color="#0000FF">Case</font>
"Display Animation List"</p>
<p style="margin-top: 0; margin-bottom: 0"> frmAni.SelfAni =
<font color="#0000FF">False</font><br>
frmAni.Show<br>
<br>
<font color="#0000FF">Case </font>"Animate"<br>
frmAni.SelfAni = <font color="#0000FF">True</font><br>
frmAni.Show</p>
<p><b>Run the program and test out our two new commands. What do you think?</b></p>
<p align="center"><font size="5"><b>System Information</b></font></p>
<p align="left"><b>Another very easy topic. Enter the following code into the
Phrase_Finish procedure:</b></p>
<p align="left"><font color="#0000FF">Case</font> "Display System Information"<br>
Shell "C:\Program Files\Common Files\Microsoft
Shared\MSINFO\msinfo32.exe", vbNormalFocus</p>
<p align="left"><b>This program will display your systems information. Our bot
has to do <i>something</i> that has to do with our computer.</b></p>
<p align="center"><font size="5"><b>Shut Down</b></font></p>
<p align="left"><b>These are the two last commands. By now, my wrists are
getting pretty sore from typing all of this! Add the following code above
everything in modMain:</b></p>
<p align="left"><font color="#0000FF">Declare Function</font> ExitWindowsEx Lib
"user32" (<font color="#0000FF">ByVal</font> uFlags <font color="#0000FF">As
Long</font>, <font color="#0000FF">ByVal </font>dwReserved <font color="#0000FF">
As Long</font>) <font color="#0000FF">As Boolean</font><br>
<font color="#0000FF">Public Const</font> EWX_LOGOFF = 0<br>
<font color="#0000FF">Public Const</font> EWX_REBOOT = 2<br>
<font color="#0000FF">Public Const</font> EWX_SHUTDOWN = 1</p>
<p align="left"><b>Now, we are almost done. As you know, we are only doing
Reboot and Shutdown. You can program Logoff, which is pathetically simple (as
you will soon see). Add the following code to finish this off:</b></p>
<p align="left"><font color="#0000FF">Case</font> "System Reboot"<br>
<font color="#0000FF">Dim</font> reboot <font color="#0000FF">
As Variant</font><br>
reboot = MsgBox("Are you sure you want to reboot?", vbYesNo,
"Reboot?")<br>
<br>
<font color="#0000FF">If</font> reboot = vbYes
<font color="#0000FF">Then</font><br>
Screen.MousePointer = vbHourglass<br>
ExitWindowsEx EWX_REBOOT, 0<br>
Unload Me<br>
<font color="#0000FF"> End<br>
End If</font></p>
<p align="left"><font color="#0000FF">Case</font> "System Shutdown"<br>
<font color="#0000FF">Dim</font> down <font color="#0000FF">
As Variant</font><br>
down = MsgBox("Are you sure you want to shutdown?", vbYesNo,
"Shutdown?")<br>
<br>
<font color="#0000FF">If</font> down = vbYes
<font color="#0000FF">Then</font><br>
Screen.MousePointer = vbHourglass<br>
ExitWindowsEx EWX_SHUTDOWN, 0<br>
Unload Me<br>
<font color="#0000FF">End<br>
End If</font></p>
<p align="center"><font size="5"><b>Tips</b></font></p>
<p align="left"><b>Well, that is it! We are done. But before I go, here are some
tips and notes:</b></p>
<ul>
<li>
<p align="left"><b>You can use Office's agents, and office can use the ones
you downloaded</b></li>
<li>
<p align="left"><b>I just scrapped the surface, there is much more to learn.</b></li>
<li>
<p align="left"><b>Add another agent, you can use more than one!</b></li>
<li>
<p align="left"><b>If you have any questions,
<a href="mailto:mTecnology@hotmail.com">E-mail</a> them to me!</b></li>
<li>
<p align="left"><b>Please Vote!!!</b></li>
</ul>
Original Comments (3)
Recovered from Wayback Machine