Allow user to build If Statements through UI options

22-degrees

Well-known member
Joined
Feb 11, 2012
Messages
156
Location
South East Ireland
Programming Experience
1-3
Hi all,

I need to provide a feature to allow a user to select one of several options form several different categories which can then be used to construct an If Statement to access data stored in arrays etc and return a result.

Basic Example: (using arbitrary headers and data)

Each header represents a combobox, each box has several options.

Argue
Stock
Oper.
Amt
Msg
IF
Apples>1Order More
AND
Oranges<2Lower Price
OR
Pears=3Give them away
ELSE
Plums<>4Dump them


So if the user selects "if", "Oranges", "<", "2", "Order More", the statement built would be:

VB.NET:
If oranges < 2 then

msgbox("Order More " & comboStock.selecteditem.tostring)

End if

In reality, the number of options and parameters are vastly greater than the demonstration above but I wanted to keep it simple. As I don't have the greatest knowledge of VB.net, I was hoping someone could provide a few keywords that I might research to hopefully achieve what I need.

What kind of options do I have, if any?
 
Last edited:
Hi,

I have not actually had need to do this myself before but what I think you need to look into is VB Scripting. This effectively allows you to create and evaluate expressions on the fly using the MSScriptControl
but I am not too sure just how powerful it actually is. Have a read of this blog that I found to get you started:-

Make your .Net application support scripting - a practical approach - Blog - Osherove

Good Luck.

Cheers,

Ian
 
That's great thanks Ian..

From initial testing it looks like it will do exactly what I need it to do.

Also there are some good keywords hidden in the comments from a previous site that used to host this person's blog so if I hit a dead-end at any point then at least I have a back-up plan.
 
Good to hear and you are welcome.

I have also looked into this a bit further and have got a good few examples of how this works which could be good for any future needs in my own programs.

Post back if you need any further help.

Cheers,

Ian
 
Back
Top