2014-04-08 137 views
0

有沒有辦法將結構「y = 3x^2-5 * x + 3」中的公式讀入VBA中,並將「y =」替換爲空白(「」)和用實際值代替x?計算公式的值

回答

1

您可以使用EVALUATE來caculate串公式

如果你有3*x^2-5*x+3(而不是3x^2-5*x+3)那麼這段代碼retruns 53

Dim strIn As String 
strIn = "3*x^2-5*x+3" 
MsgBox Evaluate(Replace(strIn, "x", "5"))