我是想这样的:
a=1
b=2
c=3
给用户在text1.text输入a+b+c或是a*b*c之类的,就可以输出值来 
就是给用户自己输入公式那样了 
请要这样的效果大概是怎样做??
谢谢!!

解决方案 »

  1.   

    用ScriptControl,你的可以实现的。
    还有一个办法是用SQL语句,
    dim userinput as string 
    userinput="a+b+c"
    set rs=CN.excute("select " & userinput & " AS Reslut FROM TABLE")
    MSGBOX RS(" Reslut")
      

  2.   

    我做了一个COM组件,如果要的话请留下你的Email
      

  3.   

    楼主是不是想要这种效果啊?
    在工程/引用中添加:Microsoft Script Control 1.0
    Private Sub Command1_Click()
        Dim StrFormulary AS String
        Dim ScrCost As New ScriptControl
        Dim SinCost As Single
        
        StrFormulary = "(1+2)/3*4"
        ScrCost.Language = "VBScript"
        SinCost = ScrCost.Eval(StrFormulary)
      Msgbox SinCost
    End Sub
      

  4.   

    楼上1,2,3 的换成变量就不行,
    a=1
    b=2
    c=3
    StrFormulary = "(a+b)/c*4"
    不是楼主的意思。
    分数太少了,这个问题并不是很简单。
      

  5.   

    Private Sub Command1_Click()
        Dim StrFormulary As String
        Dim s As New ScriptControl
        Dim a As Integer, b As Integer, c As Integer    a = 1
        b = 2
        c = 3
        'StrFormulary = Text1
        StrFormulary = "(a+b)/c"    '变量代入
        StrFormulary = Replace(StrFormulary, "a", a)
        StrFormulary = Replace(StrFormulary, "b", b)
        StrFormulary = Replace(StrFormulary, "c", c)
        '计算
        s.Language = "VBScript"
        Text1 = Text1 & " = " & s.Eval(StrFormulary)End Sub
      

  6.   

    '在TEXT输入公式,按下按钮即可计算公式的结果
    Private Sub Command1_Click()
    '引用Excel9.0对象库
    Dim xlsapp As New Excel.Application
    Dim xlsbook As Excel.Workbook
    Dim xlssheet As Excel.Worksheet
    Dim StrVar As String'xlsapp.Visible = True
    Set xlsbook = xlsapp.Workbooks.Add
    Set xlssheet = xlsbook.Worksheets(1)a = 1
    b = 2
    c = 3xlssheet.Cells(1, 1) = a
    xlssheet.Cells(2, 1) = b
    xlssheet.Cells(3, 1) = c
    StrVar = Text1.Text
    StrVar = Replace(StrVar, "a", "r[-3]x")
    StrVar = Replace(StrVar, "b", "r[-2]x")
    StrVar = Replace(StrVar, "c", "r[-1]x")
    StrVar = Replace(StrVar, "x", "c")
    StrVar = "=" & StrVarxlssheet.Range("A4").Select
    xlsapp.ActiveCell.FormulaR1C1 = StrVar
    Text1.Text = xlssheet.Cells(4, 1)Set xlssheet = Nothing
    Set xlsbook = Nothing
    Set xlsapp = NothingEnd SubPrivate Sub Form_Load()
    Text1.Text = ""
    End Sub
      

  7.   

    Private Sub Command1_Click()
        Dim StrFormulary As String
        Dim s As New ScriptControl
        Dim a As Integer, b As Integer, c As Integer    a = 1
        b = 2
        c = 3
        'StrFormulary = Text1
        StrFormulary = "(a+b)/c"    '变量代入
        StrFormulary = Replace(StrFormulary, "a", a)
        StrFormulary = Replace(StrFormulary, "b", b)
        StrFormulary = Replace(StrFormulary, "c", c)
        '计算
        s.Language = "VBScript"
    ---------------------------------------------
    为什么会报自动化错误的 提示请 指点.................    Text1 = Text1 & " = " & s.Eval(StrFormulary)End Sub
      

  8.   

    '在TEXT输入公式,按下按钮即可计算公式的结果
    Private Sub Command1_Click()
    '引用Excel9.0对象库
    Dim xlsapp As New Excel.Application
    Dim xlsbook As Excel.Workbook
    Dim xlssheet As Excel.Worksheet
    Dim StrVar As String'xlsapp.Visible = True
    Set xlsbook = xlsapp.Workbooks.Add
    Set xlssheet = xlsbook.Worksheets(1)a = 1
    b = 2
    c = 3
    StrVar = Text1.Text
    StrVar = Replace(StrVar, "a", a)
    StrVar = Replace(StrVar, "b", b)
    StrVar = Replace(StrVar, "c", c)
    StrVar = "=" & StrVarxlssheet.Range("A1").Select
    xlsapp.ActiveCell.FormulaR1C1 = StrVar
    Text1.Text = xlssheet.Cells(1, 1)xlsapp.DisplayAlerts = False
    xlsapp.QuitSet xlssheet = Nothing
    Set xlsbook = Nothing
    Set xlsapp = NothingEnd SubPrivate Sub Form_Load()
    Text1.Text = ""
    End Sub
      

  9.   

    To:jxgzay(jxgzay) 
    换成变量也是可以的啊,但是你这句好像有点不对吧:是字符类型喔,怎么可以这样用变量的??
    StrFormulary = "(a+b)/c*4"
    是不是应该这样喔
    StrFormulary="(" & a & "+" & b & ")/" & c & "*4"
      

  10.   

    以前在论坛里见有种利用个API函数来解决的办法,不用任何组件,楼主你搜索一下。
      

  11.   

    Private Sub Command1_Click()
        Dim StrFormulary As String
        Dim s As New ScriptControl
        Dim a As Integer, b As Integer, c As Integer    a = 1
        b = 2
        c = 3
        'StrFormulary = Text1
        StrFormulary = "(a+b)/c"    '变量代入
        StrFormulary = Replace(StrFormulary, "a", a)
        StrFormulary = Replace(StrFormulary, "b", b)
        StrFormulary = Replace(StrFormulary, "c", c)
        '计算
        s.Language = "VBScript"
    ---------------------------------------------
    为什么会报自动化错误的 提示请 指点.................    Text1 = Text1 & " = " & s.Eval(StrFormulary)End Sub有人试过没有 为什么会出错 
    请求指点.......................