MERLIN 的随机精选语句






1.29/5 (14投票s)
2003年12月11日
6分钟阅读

69887

836
涵盖 MSAGENT 角色 (MERLIN) 的使用和菜单构建、文本文件的读写和搜索、简单加密 (凯撒密码)
Visual Basic 6.0 的硬核教程
包括
1) MSAGENT 角色 (MERLIN) 的使用和菜单构建 2) 文本文件的读写和搜索 3) 简单加密 (凯撒密码)
4) 随机化应用程序
- 作者:J.KARTHIK (karthik_mail@indiatimes.com) (在哥印拜陀 (泰米尔纳德邦) 的 Amrita Institute of Tech 获得电气与电子工程学士学位。)
应用程序名称:JK 的段子
用法
MSAGENT 角色 Merlin 可以
- 从文本数据库中读取随机段子 (从笑话到名言)。
- 将您最喜欢的段子保存到单独的文件中 (SavedOne.txt)
- 向数据库贡献段子
- 拼写一个单词/句子。
您需要什么
- 您的系统上安装了 MSAGENT 角色 Merlin (在 c:\windows\msagent\chars\merlin.acs 中) 下载详情:Merlin( 1.8 MB ) ---> http://agent.microsoft.com/agent2/chars/Merlin.exe
- LERNOUT AND HAUSPIE 文本转语音引擎 下载详情:Lernout and Hauspie 引擎( 1MB ) -->
3) 耐心和一点点创造力 :-)
引言
我本可以直接展示源代码来开始本教程,但这不公平。最重要的是要感受到 VB 6.0 将成为激发您创造力的工具。
我将分 4 个部分讨论本教程
- MSAGENT 角色:简介 (“Hello Merlin”示例演练) Merlin 角色的 Microsoft Agent 动画 创建菜单
- 使用 VB 6.0 的简单文本文件数据库:读/写/追加 搜索
- 加密/解密:简介 VB 6.0 中的程序
- 将所有内容整合在一起 (JK_Oneliners.exe) 源代码。
现在,开始表演.....
第一节
MSAGENT 角色
i) 简介
Microsoft Agent 角色已经存在很长时间,它提供了与用户的交互式通信。通过使用 MSAGENT 角色的语音输出与用户互动是一种有趣的方式
有许多角色:巫师 Merlin;精灵 (咳咳).. 精灵;机器人 Robbie 等等.....
我想您可能熟悉 Microsoft Office 提供的动画助手,它们作为帮助助手进行交互。Microsoft 提供了一个名为 Microsoft Agent 的 SDK,它允许您在 VB 应用程序中创建和操作类似的助手。
MERLIN 在您的桌面上具有独立的移动能力,赋予角色比 Microsoft Office 中受限角色更广泛的移动范围
MSAgent.ocx (ActiveX 文件) 提供了助手的基本功能。此控件包含一个完整的对象模型,允许您执行从显示角色到响应语音命令等简单或复杂的任务。也许该控件最好的部分是您可以使用 VB5 或 VB6 以与 VB 文本框相同的方式扩展其用处。
MSAgent.ocx 提供了助手的基本功能。此控件包含一个完整的对象模型,允许您执行从显示角色到响应语音命令等简单或复杂的任务。也许该控件最好的部分是您可以使用 VB5 或 VB6 以与 VB 文本框相同的方式扩展其用处。
i) “Hello Merlin”示例演练
步骤
- 启动 VB 6.0 --> 选择新项目 --> 选择标准 EXE。您的屏幕上会出现表单。
- 选择项目 --> 组件 --> 在“控件”选项卡中选中“Microsoft Agent Control 2.0”复选框
- 您可以在工具箱中看到 Microsoft Agent 图标 (一个戴眼镜的男人,看起来像 FBI 探员 :-) )
- 现在将此控件拖放到您的表单中,并将控件命名为“ctlAgent”
- 转到您的表单 (名称:Form1) 的代码窗口并添加以下代码
Private Sub Form_Load() Form1.Hide
Dim CharPath As String 'Activate Merlin 'Charpath is the address of the merlin.acs file CharPath = "c:\windows\msagent\chars\" 'Load the character specified in Path
ctlAgent.Characters.Load "Merlin", CharPath & "merlin.acs" Set Merlin = ctlAgent.Characters("Merlin") 'Display charcter on screen
Merlin.Show End Sub
注释
有三种类型的角色文件
>.AAF 文件包含角色动画信息。 >.ACF 文件包含角色数据。 >.ACS 文件包含角色动画和角色数据。(我们使用这个)
6) 您可以在屏幕上看到巫师 Merlin。但他没有相关代码就哑巴了。接下来我们命令他说“Hello Merlin”并向我们挥手。
7) 终止应用程序运行。
ii) Merlin 角色的 Microsoft Agent 动画
按照上一节的步骤 1 到 4 操作
步骤 5 的修改代码
Private Sub Form_Load() Form1.Hide
Dim CharPath As String 'Activate Merlin CharPath = "c:\windows\msagent\chars\"
ctlAgent.Characters.Load "Merlin", CharPath & "merlin.acs" Set Merlin = ctlAgent.Characters("Merlin") Merlin.Show 'CHARACTER ANIMATIONS ( See List Below ) 'Character waves with hand
Merlin.Play "Wave"
Merlin.Speak "Hello" 'Character bows down and greets
Merlin.Play "Greet"
Merlin.Speak "Welcome" 'Character opens a book and reads
Merlin.Play "Read"
Merlin.Speak "I will be reading some random one liners" End Sub
其他可以尝试的动画
语法
CharacterName.Play "AnimationName"
动画名称
Acknowledge Announce Blink Congratulate DoMagic1 DoMagic2 Explain GestureDown GestureLeft GestureRight GetAttention LookUpBlink MoveDown MoveLeft MoveRight MoveUp Pleased Process Read Sad Search Show Think Wave Write
额外
尝试将此添加到您的代码中,以在屏幕上移动 Merlin
With Screen
CenterX = Int((.Width / .TwipsPerPixelX) / 2) CenterY = Int((.Height / .TwipsPerPixelY) / 2) End With Merlin.MoveTo CenterX, CenterY
iii) 创建菜单
当您右键单击角色时,会出现一个弹出菜单。您可以在此处添加自己的菜单并执行命令
方法如下
步骤 1:在 Private Sub Form_load () 中添加此代码
'Add all the previous code here 'Add this code after it Merlin.Commands.Add "HELLO", "HELLO", "...HELLO...", True, True Merlin.Commands.Add "EXIT", "EXIT", "...EXIT...", True, True
步骤 2:在您的代码窗口中添加此代码
Private Sub ctlAgent_Command(ByVal UserInput As Object) Select Case UserInput.Name Case "HELLO": Set Merlin = ctlAgent.Characters("Merlin") ' DON'T FORGET RE-REFERENCE MERLIN for each case Merlin.Play "Wave" Merlin.Speak "Hello" Case "EXIT": End Case Else: Set Merlin = ctlAgent.Characters("Merlin") ' DON'T FORGET RE-REFERENCE MERLIN for each case Merlin.Play "Idle1_1" End Select End Sub
步骤 3
运行。您看,弹出菜单出现了
通过添加更多菜单进行实验。
在网上对此主题进行更多研究。
现在让我们进入下一节
第二节
使用 VB 6.0 的简单文本文件数据库
i) 读/写/追加首先创建一个文本文件 (NoDat1.fil)
并填充一些内容,例如
Apple
Mac
Windows
接下来按照以下步骤读/写/追加文件。
阅读
步骤 1:打开文件进行输入
Open App.Path & "\NoDat1.fil" For Input As #1步骤 2:读取直到文件结束:EOF(文件号 #1)
Do While Not (EOF(1)) Input #1, parameter1 [, parameter2,....] 'Read the Delimited Text File and store it in parameters Loop MsgBox parameter1步骤 3:关闭文件号 #1
Close 1
如果您同时读取两个或更多文件,请使用不同的文件号 #1, #2,.....写入/追加
Open App.Path & "\NoDat1.fil" For Append As #3 Write #3, "Hello","Great"
Close #3
ii) 搜索
要执行搜索,请执行读取过程并检查搜索条件。如果为真,则退出循环。
这可能不是一个高效的搜索...但它会起作用。(尝试其他搜索方法)
代码
Open App.Path & "\NoDat1.fil" For Input As #1 Do While Not (EOF(1)) Input #1, parameter1 [,parameter2,...] If (Conditions) Then '...Do Something here... GoTo out1 End If Loop out1: '... Do something here ... Close 1
第三节
加密/解密
为什么要使用加密?为了保护关键数据不被未经授权的用户访问,或者在我的情况下,为了保护段子数据库的内容不被用户访问。
好的,我将使用一个简单的凯撒密码算法。听到这个名字不要挑眉。
替换密码最简单的例子之一是凯撒密码,据说朱利叶斯·凯撒曾用它与他的军队通信。凯撒被认为是第一个为了保护信息而使用加密的人之一。凯撒决定将消息中的每个字母移位作为他的标准算法,因此他通知了所有将军他的决定,然后能够向他们发送安全消息。
例如,您想用密钥“3”加密“HELLO”。也就是说,我们将每个字母移位 3 个位置并写下字母。
H E L L O --> K H O O R
现在将其放入代码格式。
一段代码来了....付钱吧伙计!! ;-)
Private Function CCipher(ByVal PlainText As String, ByVal ShiftSize As Integer) As String Dim CipherText As String Dim Letter As String Dim C As Integer ' Extract each alphabet and give it to the ROtate function which ' performs the rotation (encryption).
' In Rotate you have to mention the Letter extracted and by how ' much you gotta shift For C = 1 To Len(PlainText) Letter = Mid$(PlainText, C, 1) CipherText = CipherText & Rotate1(Letter, ShiftSize) Next C ' Return the Encrypted text to CCipher CCipher = CipherText
End Function Private Function Rotate1(ByVal Letter As String, ByVal ShiftAmount As Integer) As String Dim pos1 As Integer
Dim rot1 As Integer
Dim i As Integer 'Check whether the character coming in is only an Alphabet (Uppercase/Lowercase) If ((Asc(Letter) - 7) >= Asc("a") And (Asc(Letter) - 7) <= Asc("z")) Or ((Asc(Letter) - 7) >= Asc("A") And (Asc(Letter) - 7) <= Asc("Z")) Then Rotate1 = Chr$(Asc(Letter) - ShiftAmount) End If 'Do not perform encryption if the character is a Space, Period, Semicolon or Underscore If ((Asc(Letter)) = Asc(" ")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc(".")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc(";")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc("-")) Then
Rotate1 = Chr$(Asc(Letter))
End If End Function
好吧,如果你加密....总会有人解密。我们的朋友“Merlin”会解密它。
怎么做?...
只需反转加密代码
而不是
Rotate1 = Chr$(Asc(Letter) - ShiftAmount)包括这个
Rotate1_2 = Chr$(Asc(Letter2) + ShiftAmount)简单 :-)
第四节
将所有内容整合在一起 (JK_Oneliners.exe)
(按照表单上的所有说明操作,并添加两个计时器 (Timer1 - 1000 毫秒和 Timer2 - 1000 毫秒) 以同步动画另一点:文本文件 (Nodat.fil) 应包含以下格式的文本
1@@,"生存还是毁灭"
2@@,"上帝是伟大的"
等等...
现在加密此文件并将其重命名为“NoDat1.fil”此文件由 Merlin 用于读取段子。
Dim SavedOne1 As String Dim Contribute1 As String Dim Lastnum As Double Dim Spell As String Sub ReadDelimitedTextFile() Dim IndX As String Dim QQ1 As String Dim QQ2 As String Dim InRd As String Dim GDValue 'Activate Merlin again Set Merlin = ctlAgent.Characters("Merlin") '******(VER 3)******* GET THE LAST REC NUMBER Open App.Path & "\NoDat1.fil" For Input As #1 Lastnum = 0 Do While Not (EOF(1)) Input #1, IndX If (IndX >= "1" And IndX <= "5000") Then Lastnum = Val(IndX) End If ' MsgBox Lastnum Loop 'MsgBox (Lastnum) Close #1 Randomize GDValue = Int((Lastnum * Rnd) + 1) ' Open the file for Input. Open App.Path & "\NoDat1.fil" For Input As #1 InRd = GDValue Do While Not (EOF(1)) Input #1, IndX, QQ1 QQ2 = CCipher(QQ1, 7) ''*******(VER 3)********* SavedOne1 = QQ2
If (IndX = InRd + "@@" Or IndX = InRd) Then ' If (IndX = "1216@@" Or IndX = "1216") Then <-- For Testing only '(VER 1)--> MsgBox QQ2, , "JK's OneLiner #" + Str(GDValue) Merlin.Play "Read"
Merlin.Speak QQ2
'(VER 1)--> End
GoTo jack End If Loop jack: ' Close the file. Close 1 End Sub Private Sub ctlAgent_Command(ByVal UserInput As Object) Select Case UserInput.Name
Case "READ":
ReadDelimitedTextFile Case "EXIT": Timer1.Enabled = True '(VER 3) Case "SAVE": Open App.Path & "\SavedOne.txt" For Append As #3 Write #3, SavedOne1
Close #3 Case "CONTRIBUTE": Open App.Path & "\NoDat1.fil" For Input As #1 Lastnum = 0 Do While Not (EOF(1)) Input #1, IndX If (IndX >= 1 And IndX <= 2000) Then Lastnum = IndX End If ' MsgBox Lastnum Loop Lastnum = Lastnum + 1 'MsgBox (Lastnum) Close #1 Open App.Path & "\NoDat1.fil" For Append As #1 Contribute1 = InputBox("Please restrict your oneliner to 80 characters max", "JK's OneLiner Contribution") Contribute1 = CCipher_2(Contribute1, 7) Write #1, Lastnum; Contribute1
Close #1
Set Merlin = ctlAgent.Characters("Merlin") Merlin.Play "Write" Case "SPELL IT":
Spell = InputBox("Which word\sentence do you want me to spell?", "SPELL IT") Set Merlin = ctlAgent.Characters("Merlin") Merlin.Speak Spell Case "ABOUT":
Set Merlin = ctlAgent.Characters("Merlin") Merlin.Play "Announce"
Merlin.Speak "J.Karthik did his B.E EEE in Amrita Institute of Technology, Coimbator........." Merlin.Play "Search"
Merlin.Speak "He is currently residing in Bangalore and is enjoying every moment of his Life" Case Else: Merlin.Play "Idle1_1"
End Select End Sub Private Sub Form_Load() Form1.Hide
Dim CharPath As String
Dim UserName1 As String
Dim CenterX As Long
Dim CenterY As Long UserName1 = InputBox("Please type your name below", "JK's OneLiners Alpha 1.4") 'Activate Merlin CharPath = "c:\windows\msagent\chars\"
ctlAgent.Characters.Load "Merlin", CharPath & "merlin.acs" Set Merlin = ctlAgent.Characters("Merlin") Merlin.Show With Screen
CenterX = Int((.Width / .TwipsPerPixelX) / 2) CenterY = Int((.Height / .TwipsPerPixelY) / 2) End With
Merlin.MoveTo CenterX, CenterY Merlin.Play "Wave"
Merlin.Speak "Hello " + UserName1
Merlin.Play "Greet"
Merlin.Speak "Welcome to the JK's One Liners" Merlin.Play "Read"
Merlin.Speak "I will be reading some random one liners" Merlin.Play "Pleased"
Merlin.Speak "But to do that please right click me..." Merlin.Play "GetAttention"
Merlin.Speak "and select the" + EMP + " read command." Merlin.Play "Write"
Merlin.Speak "Send your feedback to karthik_mail@indiatimes.com....." Merlin.Play "Congratulate"
Merlin.Speak "...Enjoy" 'Add Commands
Merlin.Commands.Add "READ", "READ", "...READ...", True, True '(VER 3) --> ADD MENU FOR SAVING ONELINER Merlin.Commands.Add "SAVE", "SAVE", "...SAVE...", True, True Merlin.Commands.Add "CONTRIBUTE", "CONTRIBUTE", "...CONTRIBUTE...", True, True '(VER 6) SPELL IT
Merlin.Commands.Add "SPELL IT", "SPELL IT", "...SPELL IT...", True, True Merlin.Commands.Add "ABOUT", "ABOUT", "...ABOUT...", True, True Merlin.Commands.Add "EXIT", "EXIT", "...EXIT...", True, True End Sub Private Function CCipher(ByVal PlainText As String, ByVal ShiftSize As Integer) As String Dim CipherText As String
Dim Letter As String
Dim C As Integer For C = 1 To Len(PlainText) Letter = Mid$(PlainText, C, 1) CipherText = CipherText & Rotate1(Letter, ShiftSize) Next C CCipher = CipherText
End Function Private Function Rotate1(ByVal Letter As String, ByVal ShiftAmount As Integer) As String Dim pos1 As Integer
Dim rot1 As Integer
Dim i As Integer If ((Asc(Letter) - 7) >= Asc("a") And (Asc(Letter) - 7) <= Asc("z")) Or ((Asc(Letter) - 7) >= Asc("A") And (Asc(Letter) - 7) <= Asc("Z")) Then Rotate1 = Chr$(Asc(Letter) - ShiftAmount) End If If ((Asc(Letter)) = Asc(" ")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc(".")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc(";")) Then
Rotate1 = Chr$(Asc(Letter))
End If If ((Asc(Letter)) = Asc("-")) Then
Rotate1 = Chr$(Asc(Letter))
End If End Function '(VER 3)''*************** DECIPHER ********************** Private Function CCipher_2(ByVal PlainText As String, ByVal ShiftSize As Integer) As String Dim CipherText2 As String
Dim Letter2 As String
Dim C2 As Integer For C2 = 1 To Len(PlainText) Letter2 = Mid$(PlainText, C2, 1) CipherText2 = CipherText2 & Rotate1_2(Letter2, ShiftSize) Next C2 CCipher_2 = CipherText2
End Function Private Function Rotate1_2(ByVal Letter2 As String, ByVal ShiftAmount As Integer) As String Dim pos12 As Integer
Dim rot12 As Integer
Dim i2 As Integer 'pos1 = Asc(Letter) - 65
' rot1 = (pos1 - ShiftAmount) Mod 26
' Rotate1 = Chr$(65 + rot1)
If ((Asc(Letter2)) >= Asc("a") And (Asc(Letter2)) <= Asc("z")) Or ((Asc(Letter2)) >= Asc("A") And (Asc(Letter2)) <= Asc("Z")) Then Rotate1_2 = Chr$(Asc(Letter2) + ShiftAmount) End If If ((Asc(Letter2)) = Asc(" ")) Then
Rotate1_2 = Chr$(Asc(Letter2))
End If If ((Asc(Letter2)) = Asc(".")) Then
Rotate1_2 = Chr$(Asc(Letter2))
End If If ((Asc(Letter2)) = Asc(";")) Then
Rotate1_2 = Chr$(Asc(Letter2))
End If If ((Asc(Letter2)) = Asc("-")) Then
Rotate1_2 = Chr$(Asc(Letter2))
End If End Function '*******SYNC THE ANIMATIONS******* Private Sub Timer1_Timer()
Set Merlin = ctlAgent.Characters("Merlin") Merlin.Play "Hide"
Timer1.Enabled = False
Timer2.Enabled = True End Sub Private Sub Timer2_Timer()
Set Merlin = Nothing
Timer2.Enabled = False
End
End Sub
结束语
如果您觉得本教程很棒或缺少任何信息或想撞墙
请发邮件给我 ----> karthik_mail@indiatimes.com
再见