This is a sample how to evaluate complex formulas with JScript9 engine using built-in Active Scripting as provided by Windows.
https://github.com/wqweto/VBTixyLand
The idea is that with TixyScript.bas no dependency on Scripting Control is needed/used to evaluate custom JS expressions like this
Code:
'--- Form1.frm
Option Explicit
Private m_uScript As UcsActiveScriptData
Private Sub Form_Load()
If Not ActiveScriptInit(m_uScript, "JScript9", Me) Then
If Not ActiveScriptInit(m_uScript, "JScript", Me) Then
ActiveScriptTerminate m_uScript
Exit Sub
End If
End If
'--- here you can add some custom functions or constants
ActiveScriptRunCode m_uScript, "function hypot(x, y) { return Math.sqrt(x*x + y*y) }"
End Sub
Private Sub Form_Click()
Dim vResult As Variant
'--- first declare a function with two parameters which can evaluate your expression
ActiveScriptRunCode m_uScript, "function myfunc(x, y) { return (" & Text1.Text & "); }"
'--- then call this function by passing values for actual arguments
vResult = ActiveScriptCallFunction(m_uScript, "myfunc", 5, 10)
'--- show the result
MsgBox "vResult=" & vResult, vbExclamation
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Cancel = 0 Then
ActiveScriptTerminate m_uScript
End If
End Sub
The sample can evaluate an expression like x*y placed in Text1 textbox on the Form1 form.
cheers,
</wqw>