Expression Builder - Thinking of abandoning it in favour of the Scripting Control!
Ok. Here goes. Over the past few days a couple of threads had come up looking a method by which, numerical expression in a text box and/or a string variable can be evaluated at runtime, so that users may type in text in a textbox which will then be taken as an equation for evaluation.
One of them is this. I can't seem to find the other. Seems to have been deleted.
While the Script Control does have an "Eval" method, it cannot accomodate runtime variable, something like the poster in the above link was seeking.
I have attempted a crude approximation of such an Expression Builder with a function to handle creation & storage of runtime variables to be used in that builder. The class module is attached and the sample code is listed below.
Comments, ideas, corrections, please...
Especially on how to handle BODMAS in the expression.
VB Code:
Dim myEval As New cls_Exp_Build
Private Sub CreateVariables()
With myEval
.Add_New_Variable "strUserName", "String"
.Add_New_Variable "lngScoreFirst", "Long"
.Add_New_Variable "lngScoreSecond", "Long"
.Add_New_Variable "lngScoreThird", "Long"
End With
End Sub
Private Sub SetVariables()
With myEval
.Set_Var_Value("strUserName") = "KayJay"
.Set_Var_Value("lngScoreFirst") = "100"
.Set_Var_Value("lngScoreSecond") = "100"
.Set_Var_Value("lngScoreThird") = "100"
End With
End Sub
Private Sub Command1_Click()
With myEval
MsgBox "The result of the expression " & vbCrLf & vbCrLf & _