Link to home
Start Free TrialLog in
Avatar of stuart100
stuart100

asked on

VB.net Evaluate IF/Else logical expression

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!
Avatar of rajvja
rajvja
Flag of United Kingdom of Great Britain and Northern Ireland image

try this

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

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.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stuart100

ASKER

Thanks Cruiser,

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