Discussion Locked

Expression eval with MS script ctrl, VB

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hai

We want to evaluate expressions that come to the program in the form of strings and contain functions like:

TRIM
LTRIM
RTRIM
STR
MAX
MIN
.
.
.

Especially
IIF
and some user defined functions

Could any body help us with someexamples for ADDCODE() METHOD OF MS-SCRIPT CTRL.
The examples given in MSDN did'nt work.
We don't mind using the addobject() method either.
For that matter we don't mind even if you skip the MS-SCRIPT ctrl.

The expressions may look like:

IIF(PURORLEA<>"L",IIF(SCL>0,"VIE",""),"")

STR(DAY(DDAY),2)+" "+STR(MONT(DDAY),2)+" "+STR(YEAR(DDAY),4)

IIF(PURORLEA="L",IIF(LNIV>0,LR*GSTL1*PSTL1,""),IIF(NIV>0,FINRESID 0,FINRESID,""))

I can give values of the variable or replace identifers with values.

Hope some one finds a solution

Bye.

1 reply

by andrew

I had no problem with TRIM and the like, but IIF, Max & Min are not in the VBScript syntax subset.

Here's the code I used:

Private Sub Command1_Click()
MsgBox Evaluate("Trim(" & """" & " test " & """" & ")")
End Sub

Private FunctionEvaluate(sExpression As Variant) As String
Dim oScript As MSScriptControl.ScriptControl

Set oScript = New MSScriptControl.ScriptControl
oScript.Language = "VBScript"
Evaluate = oScript.Eval(sExpression)
End Function

Maybe this article will help:
http://support.microsoft.com/support/kb/articles/Q184/7/40.ASP

and this one on VBScript itself:
http://msdn.microsoft.com/scripting/vbscript/doc/vbstoc.htm

This discussion is closed to new replies.