Avatar of stuart100
 asked on

VB.net Evaluate IF/Else logical expression


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
 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.

ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon

try this

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

You need to make sure that the classes are com visible:
public class Form ...

otherwise the script control won't know how to interface back to them.
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thanks Cruiser,

That gave us a good base to start with and after lots of tinkering with the classes we got it running!
Your help has saved me hundreds of hours of internet surfing.