Private Sub Command1_Click()
Dim expr As String, code As String, result As String
' Ask for an expression, exit if Cancel was pressed
expr = InputBox$("Enter your expression", "Cheap Calculator")
If expr = "" Then Exit Sub
' Prepare the code to be passed to the Script Control,
' starting with the definition of the PI constant
code = "Const PI = 3.14159265358979" & vbCrLf _
& "Function EvalExpr" & vbCrLf _
& " EvalExpr = " & expr & vbCrLf _
& "End Function"
' Start with a "clean" control each time
' (if you omit this statement, you get an error the 2nd time
' you run this routine, because it would be an attempt to
' redefine the PI constant and the EvalExpr function
ScriptControl1.Reset
' Add the code to the Script Control
ScriptControl1.AddCode code
' Run the EvalExpr script function to evaluate the expression
result = ScriptControl1.Run("EvalExpr")
' Show the result
MsgBox expr & " = " & result, vbInformation, "Cheap Calculator"
End Sub