Skip to Content
author's profile photo Former Member
Former Member

Formula Worksheet syntax

I am working on a formula and am having some trouble with the syntax, and wondered if anyone might have any suggestions.

Here is a little background:

I have a client who wants a particular page(s) to print with the report if the entry for that report meets the a set of criteria. To do this I have placed the pages in the Report Footer and set up a formula that evaluates the criteria and suppresses the Report Footer if the entry does not meet them.

Criteria:

1. Must have a TypeField (varchar) of "A"

2. Must have a SubTypeField(varchar) of "B" or "C"

3. Must have a ClassField(varchar) of "D" or "E" and the YearField(varchar) must be <= the current year (2010) minus 50 years.

Here is my code:

// setting the year and then converting the number to a string

numberVar x := (YEAR (CURRENTDATE) - 50);

stringVar y := ToText (x);

// setting up the criteria

// the idea is that if the entry does not meet the following criteria (hence NOT),

// the page(s) in the Report Footer are suppressed

NOT

(

( {dbTable.TypeField} = "A" AND ( {dbTable.SubTypeField} = "B" OR {dbTable.SubTypeField} = "C" ) )

AND

( {dbTable.ClassField} startswith "D" AND {dbTable.YearField} <= y ) OR

( {dbTable.ClassField} startswith "E" AND {dbTable.YearField} <= y )

)

I think the issue lays in the YEAR(CURRENTDATE) process(?)

Any suggestions are welcomed.

Thanks!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 27, 2010 at 10:51 PM

    I don't think that is the problem. I suggest the following:

    // setting the year and then converting the number to a string
    numberVar x := (YEAR (CURRENTDATE) - 50);
    
    // setting up the criteria
    // the idea is that if the entry does not meet the following criteria (hence NOT),
    // the page(s) in the Report Footer are suppressed 
    NOT (
         ({dbTable.TypeField} = "A" AND (({dbTable.SubTypeField} = "B") OR ({dbTable.SubTypeField} = "C" )))
         AND ((({dbTable.ClassField} startswith "D") OR ({dbTable.ClassField} startswith "E"))
                    AND (tonumber({dbTable.YearField}) <= y)
         )
    )

    Fuskie

    Who thinks it would be easier to compare year as a numberic value and rearranged the parentheses to make them more explicit...

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Fuskie,

      Thanks for the suggestion. I took your advice on applying the tonumber conversion to the field, and making my parenthesis more explicit. Everything seems to be working now. Here is my final code- feel free to critique if you see more deficiencies.

      // this includes the full criteria which basically just adds a "when ClassField starts with D, YearField is compared to YEAR(CURRENTDATE) - 50"

      // and "when ClassField starts with E, F or G; YearField is compared to YEAR(CURRENTDATE) - 25".

      // set the numberic year values

      numberVar x := (YEAR (CURRENTDATE) - 50);

      numberVar y := (YEAR (CURRENTDATE) - 25);

      // set up the criteria

      NOT

      (

      ( {db.TypeField} = "A" AND ( ({db.SubTypeField} = "B") OR ({db.SubTypeField} = "C") ) )

      AND

      (

      ( ({db.ClassField} startswith "D") AND (tonumber({db.YearField}) <= x) ) OR

      ( ({db.ClassField} startswith "E") AND (tonumber({db.YearField}) <= y) ) OR

      ( ({db.ClassField} startswith "F") AND (tonumber({db.YearField}) <= y) ) OR

      ( ({db.ClassField} startswith "G") AND (tonumber({db.YearField}) <= y) )

      )

      )

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.