如存储公式为 :X+Y (字符串即"X+Y")
给变量X、Y赋值
将字符串公式 “X+Y” 变成 数学表达式 X+Y
用表达式进行计算

解决方案 »

  1.   

    做起来还真有点纠结……
    简单的例子:x,y的四则运算:新建一工程,添加text三个,command一个,粘贴如下代码,输入x,y的值和运算方式,按command:Private Sub Command1_Click()
        x = Val(Text1.Text)
        y = Val(Text2.Text)
        s = Text3.Text
        f = "+,-,*,/"
        ff = Split(f, ",")
        For i = 0 To UBound(ff)
            ss = Split(s, ff(i))
            If UBound(ss) > 0 Then
                If ss(0) = "x" Then
                    Select Case ff(i)
                        Case "+"
                            Print Text3.Text & "=" & x + y
                        Case "-"
                            Print Text3.Text & "=" & x - y
                        Case "*"
                            Print Text3.Text & "=" & x * y
                        Case "/"
                            Print Text3.Text & "=" & x / y
                    End Select
                End If
                If ss(1) = "x" Then
                    Select Case ff(i)
                        Case "+"
                            Print Text3.Text & "=" & y + x
                        Case "-"
                            Print Text3.Text & "=" & y - x
                        Case "*"
                            Print Text3.Text & "=" & y * x
                        Case "/"
                            Print Text3.Text & "=" & y / x
                    End Select
                End If
            End If
        Next
    End SubPrivate Sub Form_Load()
        Text1.Text = "x的值"
        Text2.Text = "y的值"
        Text3.Text = "x+y"
    End Sub
      

  2.   

    调用scriptcontrol,计算表达式。
      

  3.   

    工程中添加scriptcontrol 控件或者引用
    提取公式,使用scriptcontrol控件或者对象进行计算
      

  4.   

    http://topic.csdn.net/u/20081211/13/0ea14996-0b90-4cd0-91dc-cb558c86cee1.html
      

  5.   

    各位辛苦了,承蒙大家的帮助,使用scriptcontrol 控件,问题得到完满解决。谢谢!