这个问题我以前问过,也有好多人给过提示,可惜水平太低,依然没有解决
希望大家帮忙,具体问题请参考下面这个帖子,里面已经有一些提示。http://expert.csdn.net/Expert/topic/1893/1893465.xml?temp=.9783594我只是想识别包含+,-,*,/,以及括号之类表达式的,其他的sin之类的函数都不用识别的。如果能解决,肯定重新开帖再给300分。
还有了解ScriptControl用法的兄弟,帮忙给一个例子。下面的例子希望大家帮忙修改一下,是否可以这样来使用。Private Sub CmdRun_Click()
    Dim x1 As Integer
    Dim x2 As Integer
    Dim x3 As Integer
    Dim x4 As Integer
    Dim Expression As String
    Dim Result As Integer
    x1 = 20
    x2 = 10
    x3 = 5
    x4 = 2
    Expression = x1 - x2 + x3 * 5 + x4 / 2
    Result = ScriptControl.ExecuteStatement(Expression)
    TxtResult.Text = Result
End Sub

解决方案 »

  1.   

    识别的思路就是
    http://expert.csdn.net/Expert/topic/1893/1893465.xml?temp=.9783594
    所说的了,问题是你打算怎样求极值?建议好好复习一下数学知识
      

  2.   

    Private Sub CmdRun_Click()
        Dim x1 As Integer
        Dim Expression As String
        Dim Result As Integer
        Dim sc As New ScriptControl
        Set sc = CreateObject("ScriptControl")
        sc.Language = "vbscript"
        sc.AddCode ("Dim x1")
        sc.AddCode ("Dim x2")
        sc.AddCode ("Dim x3")
        sc.AddCode ("Dim x4")
        sc.AddCode ("x1 = 20")
        sc.AddCode ("x2 = 10")
        sc.AddCode ("x3 = 5")
        sc.AddCode ("x4 = 2")
        sc.AddCode ("Expression = x1 - x2 + x3 * 5 + x4 / 2")
        sc.AddCode ("GetResult =Expression")
        Result = sc.Eval("GetResult")
        txtResult.Text = Result
    End Sub
      

  3.   

    先添加一个文本框(textbox)
    在textbox的keydown事件里这样写:
    if keycode < 48 or keycode >57 then 
       msgbox "输入的不是数字.不接受!"
    if len (text1.text) > 0 then
       text1.text=len(text1.text,len (text1.text)-1)
    end if 
    exit sub仅此为例...小弟水平不高...但是希望可以帮到你...
      

  4.   

    其余的请参看ASC码值.
    数字的asc码值在48--57 之间