Skip to content

Commit def8d85

Browse files
committed
Usage examples have been added
1 parent 53b7271 commit def8d85

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

+56
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,62 @@ However, matrix functions need to take care of creating arrays from a string, th
8787

8888
As an illustration, the `UDFunctions.cls` module has an implementation of the `DET` function with an example of using the array handle function. In addition, the `GCD` function is implemented as a demo.
8989

90+
## Using the code
91+
VBA Expressions is an easy-to-use library, this section shows some examples of how to use the most common properties and methods
92+
93+
```
94+
Sub SimpleMathEval()
95+
Dim Evaluator As VBAexpressions
96+
Set Evaluator = New VBAexpressions
97+
With Evaluator
98+
.Create "(((((((((((-123.456-654.321)*1.1)*2.2)*3.3)+4.4)+5.5)+6.6)*7.7)*8.8)+9.9)+10.10)"
99+
If .ReadyToEval Then 'Evaluates only if the expression was successfully parsed.
100+
.Eval
101+
End If
102+
End With
103+
End Sub
104+
Sub LateVariableAssignment()
105+
Dim Evaluator As VBAexpressions
106+
Set Evaluator = New VBAexpressions
107+
With Evaluator
108+
.Create "Pi.e * 5.2Pie.1 + 3.1Pie"
109+
If .ReadyToEval Then
110+
Debug.Print "Variables: "; .CurrentVariables 'Print the list of parsed variables
111+
.Eval ("Pi.e=1; Pie.1=2; Pie=3") 'Late variable assignment
112+
Debug.Print .Expression; " = "; .Result; _
113+
"; for: "; .CurrentVarValues 'Print stored result, expression and values used in evaluation
114+
End If
115+
End With
116+
End Sub
117+
Sub EarlyVariableAssignment()
118+
Dim Evaluator As VBAexpressions
119+
Set Evaluator = New VBAexpressions
120+
With Evaluator
121+
.Create "Pi.e * 5.2Pie.1 + 3.1Pie"
122+
If .ReadyToEval Then
123+
Debug.Print "Variables: "; .CurrentVariables
124+
.VarValue("Pi.e") = 1
125+
.VarValue("Pie.1") = 2
126+
.VarValue("Pie") = 3
127+
.Eval
128+
Debug.Print .Expression; " = "; .Result; _
129+
"; for: "; .CurrentVarValues
130+
End If
131+
End With
132+
End Sub
133+
Sub TrigFunctions()
134+
Dim Evaluator As VBAexpressions
135+
Set Evaluator = New VBAexpressions
136+
With Evaluator
137+
.Create "asin(sin(30))"
138+
If .ReadyToEval Then
139+
.Degrees = True 'Eval in degrees
140+
.Eval
141+
End If
142+
End With
143+
End Sub
144+
```
145+
90146
## Licence
91147

92148
Copyright (C) 2022 [W. García](https://github.com/ws-garcia/).

0 commit comments

Comments
 (0)