首先引用一个控件到桌面 Microsoft script control 1.0 然后写代码 Dim x As String Dim str As String Dim num1 As Integer Dim num2 As Integer num1 = 10 num2 = 20 x = ">" str = num1 & x & num2 Debug.Print ScriptControl1.Eval(str) End SubVB6.0 调试通过 你的要求请自己改代码!!
Public Function Func(fun As String, x As Double, Optional y As Double = 0, Optional z As Double = 0) As Double fun = Replace(fun, "x", CStr(x)) fun = Replace(fun, "y", CStr(y)) fun = Replace(fun, "z", CStr(z)) Set scr = CreateObject("MSScriptControl.ScriptControl") scr.Language = "vbscript" Func = scr.Eval(fun) End FunctionPrivate Sub Command1_Click() Dim fun As String fun = "sin(x)*x^2+y^3+cos(z)" MsgBox Func(fun, 3, 4, 8) End Sub
Microsoft script control 1.0
然后写代码
Dim x As String
Dim str As String
Dim num1 As Integer
Dim num2 As Integer
num1 = 10
num2 = 20
x = ">"
str = num1 & x & num2
Debug.Print ScriptControl1.Eval(str)
End SubVB6.0 调试通过
你的要求请自己改代码!!
fun = Replace(fun, "x", CStr(x))
fun = Replace(fun, "y", CStr(y))
fun = Replace(fun, "z", CStr(z))
Set scr = CreateObject("MSScriptControl.ScriptControl")
scr.Language = "vbscript"
Func = scr.Eval(fun)
End FunctionPrivate Sub Command1_Click()
Dim fun As String
fun = "sin(x)*x^2+y^3+cos(z)"
MsgBox Func(fun, 3, 4, 8)
End Sub