VB.net Evaluate IF/Else logical expression

stuart100
stuart100 used Ask the Experts™
on
Greetings,

I am trying to evaluate an IF/Else expression (using .Net 2.0). The expression (sValidation) comes from the database, and will be used to validate the values entered into a form by the user. The following is a sample of sValidation:

If Form.Data.Field("Test Name").Value = "Testing one...two...three" Then
 Return True
Else
 Return False
End If

I tried using MSScriptControl, but have been unsuccessful. Using the EVAL(sValidation) I get a syntax error. If I put sValidation within a function (sCode), addCode(sCode) and use the RUN(sCode) then I get a "Class doesn't support Automation: 'Form.Data.Field'" error.

Form, Data, and Field are classes I built, and I think that's where it's getting hung up. I tried to addObject for the class, and I also tried to add the class code to sCode, but still no avail. (If I pass the actual value of "Form.Data.Field("Test Name").Value" as a parameter in sCode, then the expression is evaluated correctly - hence why I think it's the class...but I could be wrong)

Has anyone else had success evaluating this type of expression using classes?

Any suggestions of solving this, either with MSScriptControl or another method would be fantastic.

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
try this

If Form.Data.Field("Test Name").Value.ToString() = "Testing one...two...three" Then
 Return True
Else
 Return False
End If
You need to make sure that the classes are com visible:
[ComVisible(true)]
public class Form ...

otherwise the script control won't know how to interface back to them.
Most Valuable Expert 2012
Top Expert 2014
Commented:

Author

Commented:
Thanks Cruiser,

That gave us a good base to start with and after lots of tinkering with the classes we got it running!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial