Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011

    Unanswered: Need To Save Formula

    I need to save formula into table with their Id
    Like: A<12&&String1.equals(String2)

    whatshould i use to do this..
    There is a idea to use excel to save formula and access the formula to know the result but i don't to know how to use excel with Mysql,Hibernate And ejb,
    i need to save this excel into server and save their address into column..

    Hope u understand what i want ..

  2. #2
    Join Date
    Jun 2007
    Some ideas
    • The formula name should go into a separate field.
    • I'd put delimiters around the variables so they're easier to spot.
    • You should allow spaces in your formulas otherwise they'll be a pain to read.
    • I'd have a separate table to provide descriptions for variables.
    • You could also use either table to store constants and their values (see Pi below).
    • I'd also have a description field in the formula and variable tables.
    • As well as substituting variables with their values you could also do the same with constants and other formulas stored in the table - this makes it much more powerful (see Area below).

    create table Replacements(
       name    varchar(1000),
       type      varchar(12),
       value    varchar(1000),
       desc     varchar(1000)
    insert Replacements (name, type, value, desc) 
    values ("Cm2Inch", "Formula", "{cm} * 0.394", "Convert cm to inches" )
    insert Replacements (name, type, value, desc) 
    values ("cm","Variable","192","height in cm" )
    insert Replacements (name, type, value, desc) 
    values ("Pi", "Constant", "3.14159265", ""Value of Pi" )
    insert Replacements (name, type, value, desc) 
    values ("Area","Formula","{x} * {y}", "Formula for area" )
    insert Replacements (name, type, value, desc) 
    values ("Volume","Formula", "{area} * {z}", "Formula for volume" )
    You'd then just look at your string and replace any name in curly brackets with it's value. You'd keep doing this until no replacement has been done or a maximum number of replacements have been done (say 100). If there is still a name in curly brackets then this means that variable couldn't be found. Remember to check for errors when you run the formula!

    Using the same table for formula, constants and variables makes the system easier to write and more powerful but it does mean you have to check for errors etc - that's your choice. You'll want to change the names of the fields as they're keywords.
    Last edited by mike_bike_kite; 04-20-11 at 08:11.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts