Question dynamic evaluation and verification of controls at runtime

rvandervalk

New member
Joined
Mar 5, 2015
Messages
3
Programming Experience
10+
My application requires the ability to have the end user specify a verification condition for a form. So, if a form contains text fields A, B, and C the user may specify that, for example, A = B or B = C in order for the form to be valid. This verification condition is not known at development time, only at runtime, so my issue is how evaluate or "execute" the string which contains this validation code? I tried the Jscript Eval function, but could not figure out how to pass the field values from my form to the eval function. Has anybody come up with a solution for something like this? Thanks in advance.
 
Please post some code and I might be able to assist you. I'm not familiar with the eval function but if I could see some code and a picture of your form I may be of assistance.

Using vague terms like "execute" the string is very unhelpful to anyone who might be able to help you. Please understand something you call a "verification condition" has no meaning outside of your application. Give me a better idea of what you're working with and I will most certainly be able to assist.
 
Thanks for the quick reply. It's actually a pretty simple problem, I just didn't describe it adequately. Basically I have a windows form. This form has fields that the user fills in. In order for the form to be valid certain fields must have certain values. Sometimes, to be valid one field has to be compared to another field on the same form (for example, a user might say that for two of the fields, one must be filled in... they can't both be blank).

The issue is that the rules that determine what makes the form valid are not hardcoded. The actual fields and the rules that make the form valid change from customer to customer. The way the rules are communicated to the program are via a text string. The contents and format of this text string is not yet determined, but must be something that would communicate the "rules" to the program. An example of what this string might look like is [FieldA <> "" or FieldB <> ""] assuming FieldA and FieldB are both fields in the form. Again, the exact contents of this string is not important. What is important is that the contents of this string be able to convey to the program what needs to be true in order for the form to be considered "valid". If the rules are not met, an error msg can be given to the end user and they can then change the data in the form such that the form is then "valid".

So, the issue is that these rules are not hardcoded but need to be somehow communicated to the program, and the program must then look at these rules and process them properly. That's the problem. I cannot find or think of a way to do this "ad hoc" evaluation at runtime. The Jscript reference is probably not important. I pointed it out because somebody else had mentioned that Jscript has a function to evaluate (EVAL function) a statement passed to it at runtime. So Eval("1+2") would return a value of 3. So I tried to figure out if the EVAL function could help me in this case.... it didn't seem to apply.

Bottom line is that I need a way to take this VB code:
If FieldA <> "" or FieldB <> "" then
return "error"
endif
<continue processing>
and have that type of processing done without hardcoding it. Again, the actual conditional will be determined at runtime.

Hope this makes my problem a little clearer. Thanks for any help you can provide.
 
would I be right in understanding from this that what you want is for the user to be able to dynamically change the variable relationships and the operator of that relationship.

e.g. you have four fields, named field1, field2 etc.

you want to create a relationship between any of those 4 fields using any operator set by the user e.g. the user can say field1 <>field2 AND field3=field4

or equally set it to field1 = field3 OR field2 = field4 etc. etc.?
 
Yes, almost totally correct. Actually what is happening is that many different customers (ie different companies) will use this and each of them will have a different set of rules determining what makes the form complete and valid. They will communicate to me the rules they want enforced, and I will be the one to create a "string" specifying their requirements. This string may be one field, or relationships between multiple fields. Total number of fields to be validated can be 0 up to (theoretically) the number of fields on the form (although in reality I would expect just a small subset of the fields needing to be checked).
What I DON'T want to do is "hard code" each validation by customer, as I feel that is not a very elegant solution, and very restricting if the rules for the customer ever change.
So, basically, the code needed to do any of the validations would be simple and straightforward, BUT the program just won't know what the validation rules are until runtime.
 
I'd be tempted to take a poor route and have a hidden admin menu that lets you alter the evaluation routine in a text box, take the field values into a datatable and use datatable.compute with the string.
 
Back
Top