references VBScript library, use its Eval Functiontext1.text = Eval("2+3")

解决方案 »

  1.   

    我怎麼找不到 VBScript library
      

  2.   

    '先引用Microsoft Script Control
    Dim sc As New ScriptControl
    sc.Language = "vbscript"
    Text1.Text = sc.Eval(Text1.Text)
      

  3.   

    只有Microsoft VBScript Reqular Expression
    和  Microsoft VBScript Globals
    都沒有Eval
      

  4.   

    还可以用mid 把"2+3"分解成 "2" "+" "3" 用Val把"2"、"3"转换成数值
    再相加!!
      

  5.   

    回复人: acptvb(微软全球技术中心 VB技术支持) (  ) 信誉:99  2002-6-26 16:53:41  得分:0  
     
     
      感谢您使用微软产品。您可以利用Microsoft Script Control来实现这个功能。首先,你需要在工程里引用一下Microsoft Script Control。然后加入一下代码:Private Sub Form_Load()Dim scr As New ScriptControl
    Dim mycode As Stringscr.Language = "vbscript"
    mycode = "public function Test()" + vbCrLf
    mycode = mycode + "MsgBox ""Hello VB""" + vbCrLf
    mycode = mycode + "End function"scr.AddCode (mycode)
    scr.Eval ("Test()")End Sub这样,在字符串mycode里定义的函数Test()就会被调用了。参考:HOWTO: Use Script Control Modules and Procedures Collections 
    http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q184745
    -  微软全球技术中心 VB技术支持本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查
    (http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  6.   

    各位老大,我怎么找不到Microsoft Script Control,是不是我的vb6.0有问题?
      

  7.   

    you can download it at
    http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/732/msdncompositedoc.xml&frame=true