Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Evening. I have datatable with 5 columns through which I loop. Within the loop is an if statement checking the entry (row) in each of the columns individually and giving a certain outcome. The columns are defined as H1, H2, H3, H4, H5.

I want to create on the userform an user input, where the user can define the logic of the if statement. For instance, a text box maybe, that the user can input the following logic (H1>a) or (H2>a And H3<b).>

This should then be added to the if statement automatically.

Any suggestions, please

What I have tried:

I have using a lot of text box and fixing/limiting the inputs in the textbox, for instance textbox 1 can you can only choose H1 with > signs etc, but this is too limited.
Posted
Updated 23-Mar-16 12:17pm

different approach

have a look at DataTable.Select Method (String) (System.Data)[^]

gets you all the rows matching the given Expression
lots of possibility's like
H1 like "F*"
 
Share this answer
 
Comments
Sascha Lefèvre 23-Mar-16 18:19pm    
Didn't think of that! My 5
Matt T Heffron 23-Mar-16 19:04pm    
+5
Take a look at this CodeProject article: Dynamic Expresso[^]

It's written in C# but you can use it as a DLL from VB.NET.

It allows you to do something like this (also C#, I'm not "fluent" with VB.NET, I hope you can read it):
C#
string expression = // expression entered by user, e.g. "(H1>1) or (H2>1 and H3<2)"

var interpreter = new Interpreter();

interpreter.SetVariable("H1", dataTable.Rows[currentRow]["H1"]);
interpreter.SetVariable("H2", dataTable.Rows[currentRow]["H2"]);
interpreter.SetVariable("H3", dataTable.Rows[currentRow]["H3"]);

var detectedIdentifiers = interpreter.DetectIdentifiers(expression);

if (detectedIdentifiers.UnknownIdentifiers.Any())
{
   // show error message about invalid identifiers
   // (e.g. user entered "H4" or something completely different)
}

bool result = interpreter.Eval<bool>(expression);
 
Share this answer
 
v2
Comments
Matt T Heffron 23-Mar-16 19:04pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900