Results 1 to 28 of 28

Thread: Expression Builder - Thinking of abandoning it in favour of the Scripting Control!

Threaded View

  1. #1

    Thread Starter
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849

    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:
    1. Dim myEval As New cls_Exp_Build
    2.  
    3. Private Sub CreateVariables()
    4. With myEval
    5.     .Add_New_Variable "strUserName", "String"
    6.     .Add_New_Variable "lngScoreFirst", "Long"
    7.     .Add_New_Variable "lngScoreSecond", "Long"
    8.     .Add_New_Variable "lngScoreThird", "Long"
    9. End With
    10. End Sub
    11.  
    12. Private Sub SetVariables()
    13. With myEval
    14.     .Set_Var_Value("strUserName") = "KayJay"
    15.     .Set_Var_Value("lngScoreFirst") = "100"
    16.     .Set_Var_Value("lngScoreSecond") = "100"
    17.     .Set_Var_Value("lngScoreThird") = "100"
    18. End With
    19. End Sub
    20.  
    21. Private Sub Command1_Click()
    22. With myEval
    23.  
    24. MsgBox "The result of the expression " & vbCrLf & vbCrLf & _
    25.          Text1.Text & vbCrLf & vbCrLf & _
    26.          "is " & .Numerical_Evaluation(Text1.Text)
    27.  
    28. MsgBox "The average score of " & _
    29.         .Get_Var_Value("strUserName") & _
    30.         " is " & _
    31.         .Numerical_Evaluation(.Get_Var_Value("lngScoreFirst") & _
    32.         " + " & _
    33.         .Get_Var_Value("lngScoreSecond") & _
    34.         " + " & _
    35.         .Get_Var_Value("lngScoreThird") & _
    36.         " / 3")
    37.  
    38. MsgBox .Get_Var_Value("strUserName") & _
    39.         "'s average score is " & _
    40.         .Numerical_Evaluation("Avrge " & .Get_Var_Value("lngScoreFirst") & _
    41.         "," & _
    42.         .Get_Var_Value("lngScoreSecond") & _
    43.         "," & _
    44.         .Get_Var_Value("lngScoreThird"))
    45.  
    46. End With
    47.  
    48. End Sub
    49.  
    50. Private Sub Form_Load()
    51. Call CreateVariables
    52. Call SetVariables
    53.  
    54. Text1.Text = "lngScoreFirst + lngScoreSecond + lngScoreThird / 3"
    55. End Sub
    Attached Files Attached Files
    Last edited by KayJay; Jan 31st, 2003 at 06:45 AM.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width