Trying to make the following work:
Sub Test()
Dim condition As String
Dim comparison As String
condition = "({0} > {1} And ({1} = 2 Or {2} <> 3))"
Dim variable As String
variable = StringFormat(condition, 3, 2, 4)
Debug.Print variable
Dim result As Variant
result = Evaluate(variable)
Debug.Print result
End Sub
Public Function StringFormat(mask As String, ParamArray tokens()) As String
Dim i As Long
For i = LBound(tokens) To UBound(tokens)
mask = Replace$(mask, "{" & i & "}", tokens(i))
Next
StringFormat = mask
End Function
and somehow this is what I got in the immediate window:
which is rather ok, but when I try to evaluate the first line I get the result I am expecting:
Changing the condition to
condition = "({0} > {1})"
works.
Any idea how to evaluate this: ({0} > {1} And ({1} = 2 Or {2} <> 3))
with the Evaluate()
method?