Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

User Defined Conditions

Options
  • 20-02-2013 9:58pm
    #1
    Registered Users Posts: 2,815 ✭✭✭


    (I'm using VB as my example code here but this question is applicable to any major OOP language. I'll be using Java for this application though)

    In a nutshell, I'm looking to know what the standard methodology is for coding user defined criteria (such as Excel's conditional formatting)

    For example, let's say I have a commission system with the following code:
    if sales < 100 and empCategory = "junior" then
         commRate = 0.50
    elseif sales < 100 and empCategory = "senior" then
         commRate = 0.60
    elseif sales >= 100 and sales <1000 then
         commRate = 0.70
    else
         commRate = 0.80
    end if
    

    So, in this example the logic that determines the commission rate is hardcoded. However, I want to take this logic out of the hardcoded code and allow the user to add, modify and delete these criteria using boolean and conparison operators against fields in the db (again, just like Excel conditional formatting)

    Note I'm using the setting of a variable as an example. Instead, I could be calling another procedure based on the criteria?


    Also, please note that the above example is very simplistic. The calculations in real life will involve a much more complex formula that uses most of the boolean operators with nested statements. There will almost always be an "else" case if no condition is met. Finally, this will be applied to each row is a fairly large recordset.


    Designing the GUI for this isn't a problem, but I'm unsure:
    • Where to store the user's conditions (in a db table, in an XML, etc...)?
    • How to set the commRate variable if the boolean/comparison operators and indeed the very structure of the boolean statement (i.e nested statement) isn't hardcoded


    I'm stumped how to achieve this if I'm not actually using the boolean/comparison operators in my actual code, but I know it is possible. I know you can use a binary tree data structure to work with maths formulae but I'm unsure if I'm on the right track.


    I'd appreciate any advice.


    Thanks


Advertisement