Home pageFind It!Contact JeksJeks documentation

Jeks

 Jeks forum

This forum is dedicated to Jeks.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject Combination of String and Number expressions

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 11:37 AM
Hi,

Is it possible to combine String and numeric expression checks in a rule? If so any pointers on what to do?

For example:

IF( AND( 20.12 >= 11.13, 'P' = 'P' ))

Thanks for any help

Andez


---
Andez

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Oct 1, 2010 at 11:43 AM
Strings must be noted between " ".
For example,
  =IF( AND( 20.12 >= 11.13, "P" = "P" ), "yes", "no")
is a valid expression

---
Manu (moderator/modérateur)

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 12:06 PM
Hi,

It's not working for me...

I have the following code declarations:

ExpressionParser parser = new ExpressionParser(new JeksExpressionSyntax(), null);
JeksInterpreter interpreter = new JeksInterpreter();

CompiledExpression exp = parser.compileExpression("=" + parsedRule);
result = exp.computeExpression(interpreter);

And the expression I am are trying to evaluate in this instance is:

=IF( AND( "Missing" = "Missing", "P" = "P" ),"no", "yes")


Any ideas?

Thanks

Andez
---
Andez

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 12:09 PM
I get the following exception:

SEVERE: AWT-EventQueue-0java.lang.IllegalArgumentException: Operand Missing not an instance of Number or Boolean
at com.eteks.parser.WrapperInterpreter.checkOperandsInstanceOfNumberOrBoolean(WrapperInterpreter.java:480)
at com.eteks.parser.WrapperInterpreter.getBinaryOperatorValue(WrapperInterpreter.java:388)
at com.eteks.jeks.JeksInterpreter.getBinaryOperatorValue(JeksInterpreter.java:107)
at com.eteks.parser.node.BinaryOperatorNode.computeExpression(BinaryOperatorNode.java:100)
at com.eteks.parser.node.FunctionNode.computeExpression(FunctionNode.java:110)
at com.eteks.parser.node.FunctionNode.computeExpression(FunctionNode.java:110)
at com.eteks.parser.CompiledExpression.computeExpression(CompiledExpression.java:216)
---
Andez

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 12:29 PM
Also, with the expression:

=IF( AND( 20.12 >= 11.13, "P" = "P" ), "yes", "no")

I get the exception message "Operand P not an instance of Number or Boolean".

Please help me as I don't know what I am doing wrong.

Thanks

Andez
---
Andez

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 12:32 PM
Also in the Jeks Spreadsheet Demo, I get #VALUE in the cell.

Andez
---
Andez

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Oct 1, 2010 at 1:53 PM
I'm sorry it works in my version under development but not with version 1.0.2.
You can fix this problem now by simply overriding the getBinaryOperatorValue method in JeksInterpreter, like this:

    Interpreter interpreter = new JeksInterpreter() {
      public Object getBinaryOperatorValue (Object binaryOperatorKey, Object param1, Object param2)
      {
        // Only functions may take a cell set as parameter
        if ( param1 instanceof JeksCellSet
            || param2 instanceof JeksCellSet)
          throw new IllegalArgumentException ();
        // Enabled comparison between any type supported by Jeks
        else if (binaryOperatorKey.equals (JeksExpressionSyntax.OPERATOR_EQUAL))
          return param1 != null && param1.equals (param2)
                   ? Boolean.TRUE : Boolean.FALSE;
        // Enabled comparison between any type supported by Jeks
        else if (binaryOperatorKey.equals (JeksExpressionSyntax.OPERATOR_DIFFERENT))
          return param1 != null && param1.equals (param2)
                   ? Boolean.FALSE : Boolean.TRUE;
        else
          return super.getBinaryOperatorValue (binaryOperatorKey, param1, param2);
      }
    };


I should really finish and release the version I started programming. It has many additional nice features (book management, cell format dialog...), but Sweet Home 3D takes a lot of my time now.
Why are you interested by Jeks?
---
Manu (moderator/modérateur)

Andez

Location : Durham, UK
Member since : Oct 1, 2010
Messages : 6
 Oct 1, 2010 at 2:27 PM
Thanks for that. I will give it a go.

We bought your Jeks Parser many moons ago (for Quorum Dev) and it is still used in our application and I need to modify the functionality to allow it to use string comparisons.

I am still relatively new to Java (about a year now) - I'm more a .NET background for my sins.

Thanks Andez
---
Andez

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Oct 1, 2010 at 2:43 PM
I'm glad you still use Jeks six years later... ;-)
---
Manu (moderator/modérateur)


Home pageFind It!ContactTop

© Copyrights 1997-2023 eTeks - All rights reserved

JeksJeks documentation