1)debug.print 是不是你加进去的代码?2)这段代码如果去掉debug.print...,就是VBScript代码。VBScript和VB不一样,只有Variant数据类型,没有String和Object, window的scripting engine负责转换适当的类型。3)去掉所有的debug.print,这段代码另存为test.html,用IE打开试试看。<body>
<script language="vbscript">
Dim agt   As New AgentObjects.Agent
Dim actor As AgentObjects.IAgentCtlCharacterExSub demo()
  dim name 'as variant '************************* A
  agt.Connected = True
  agt.Characters.Load("me")
  Set actor = agt.Characters.Item("me")
  With actor
    .Activate
    .Show
    'debug.print(vartype(.AnimationNames )) '************* B
    For Each Name In .AnimationNames '*************** C
     ' debug.print vartype(Name) '**************** D
      .Play Name '**************** E
    Next
  End With
End Sub
</script>
<button onclick="demo()">Agent演示</button>
</body>我没有装Agent,所以不能帮你测试。驻好运

解决方案 »

  1.   

    ''' VB中的 agent Hello world example:
    '''''''''''''''
    ''''   hello.frm
    ''''''''''''''
    VERSION 5.00
    Object = "{F5BE8BC2-7DE6-11D0-91FE-00C04FD701A5}#2.0#0"; "AgentCtl.dll"
    Begin VB.Form Form1 
       Caption         =   "Hello, World"
       ClientHeight    =   1680
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   1680
       ScaleWidth      =   4680
       StartUpPosition =   3  'Windows Default
       Begin VB.TextBox TextBox 
          Appearance      =   0  'Flat
          Height          =   615
          Left            =   240
          MultiLine       =   -1  'True
          TabIndex        =   1
          ToolTipText     =   "Type something in here for the Genie to say, then press the Say it! button"
          Top             =   120
          Width           =   4335
       End
       Begin VB.CommandButton Button 
          Caption         =   "Say it!"
          Height          =   495
          Left            =   1920
          TabIndex        =   0
          ToolTipText     =   "Type some text into the text box, then press this button to hear Genie say it"
          Top             =   960
          Width           =   1215
       End
       Begin AgentObjectsCtl.Agent Agent1 
          Left            =   240
          Top             =   960
          _cx             =   847
          _cy             =   847
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Dim Genie As IAgentCtlCharacterEx
    Const DATAPATH = "genie.acs"
    Private Sub Form_Load()
        Agent1.Characters.Load "Genie", DATAPATH
        Set Genie = Agent1.Characters("Genie")
        Genie.LanguageID = &H409
        TextBox.Text = "Hello World!"
    End SubPrivate Sub Button_Click()
        Genie.Show
        Genie.Speak TextBox.Text
        Genie.Hide
    End Sub'''''''''''
    ' hello.vbp
    '''''''''''
    Type=Exe
    Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINNT\System32\StdOle2.tlb#OLE Automation
    Object={F5BE8BC2-7DE6-11D0-91FE-00C04FD701A5}#2.0#0; AgentCtl.dll
    Form=Hello.frm
    Startup="Form1"
    HelpFile=""
    Command32=""
    Name="Project1"
    HelpContextID="0"
    CompatibleMode="0"
    MajorVer=1
    MinorVer=0
    RevisionVer=0
    AutoIncrementVer=0
    ServerSupportFiles=0
    VersionCompanyName="Microsoft"
    CompilationType=0
    OptimizationType=0
    FavorPentiumPro(tm)=0
    CodeViewDebugInfo=0
    NoAliasing=0
    BoundsCheck=0
    OverflowCheck=0
    FlPointCheck=0
    FDIVCheck=0
    UnroundedFP=0
    StartMode=0
    Unattended=0
    ThreadPerObject=0
    MaxNumberOfThreads=1
      

  2.   

    to onestab(┼─):
    1) debug.print的确是我自己加的
    2) 那段代码是我在VB里运行的. 不管Vbscript是怎么处理的,我只想知道在VB里,如果解释通那段代码
    3) HTML是可以得
    4) 你后来那段代码是Design Time时用了Agent ActiveX Control把,我是在Run Time创建Agent对象的(添加了相关引用)谢谢关注
    请继续帮忙
      

  3.   

    个人认为 Name 为VB中的保留字,所以不可以再定义。出现上述错误。
      

  4.   

    1)AnimationNames 集合中存储的是variant/string类型的,也就是variant类型的和普通的string不同,所以name不能声明成string
    2)string类型是可以放在collection中的,Collection实际是一个SAFEARRAY可以存放任何类型的数据, AnimationNames 继承了一个标准的Collection的接口,也就是有一个枚举借口,只要有这个就可以用For each next来遍历集合中的成员
      

  5.   

    2) 你的回答是正确的.我搞错了. 不过你说: Collection实际是一个SAFEARRAY可以存放任何类型的数据. 可是我记得自定义的好像不行,如:
    Type StateData
     a As Integer
     b As Integer
    End TypeSub test()
    Dim c As New Collection
    Dim sd As StateData
    c.Add sd
    End Sub1) 既然AnimationNames 集合中存储的是variant类型的,那为什么vartype(Name) 显示是String而不是Variant? 谢谢
      

  6.   

    返回的可能是Collection,一般用Variant对象.
    比如做三层架构,中间层不想做collection,直接返回Recordset的Varient也可以的.---------------------------------------------------------
    Montaque==Digitalboy==Houyongfeng==Monkey
      

  7.   

    至于为什么vartype(Name) 显示是String而不是Variant? 
    这是因为Variant类型一旦被负值,他的类型就会变成实际值的类型,但又不同于实际值的类型,他会在实际的数据前用几个字节来储存后面数据的类型
    当VB用“=”负值时,VB会自动进行转换,用For each next时是由AnimationNames 集合的枚举接口来副职的,就不会进行自动的转换
    另一方面,vartype函数只有在是Variant数组时才会返回variant类型(见MSDN)
      

  8.   

    至于自定义的类型如何放入Collection
    我试了一下,VB说只有在public object module中才行,也就是说放在ActiveX Dll的Class中是可以的,测试通过。
      

  9.   

    Collection是一集合,它可以包含任何类型的数据。
    ================================================================
    我是一个兵,来自老百姓。