Community articleUFLSetFormula function
Added by IBM contributorIBM on August 16, 2011
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.



Description

This function sets the formula for a node.

Function

   r_short UFLSetFormula(
      formNodeP aNode,
      r_charP theFormula
   );


Parameters

Table 1. Function parameters
ExpressionTypeDescription
aNode formNodePThe formNodeP to set the formula for.
theFormular_charPThe formula to assign to the aNode. If NULL, the formula is assigned as NULL.


Returns

OK on success or an error code on failure.

Example

In this example, UFLDereferenceEx is used to locate an age field. UFLSetFormula is then used to set the appropriate formula for the field.
   r_error setFormula(formNodeP form, int curMonth, int curDay, 
      int birMonth, int birDay)
   {
   formNodeP tempNode=NULL;
   r_error error=OK;
 
      if ((tempNode = UFLDereferenceEx(form, NULL, "PAGE1.AGEFIELD.value", 
         0, UFL_OPTION_REFERENCE | UFL_SEARCH_AND_CREATE, NULL)) == NULL)
      {
         fprintf(stderr, "Could not locate AGEFIELD node.\n");
         return(NOTOK);
      }
 
   /* The following logic simply identifies how the formula should be set. If
      the current date is later in the year than the birth date, then the age
      is: current year - birth year. If the current date is earlier in the
      year then the birth date, then the age is: current year - birth year -
      1. */
 
      if ((curMonth > birMonth) || ((curMonth == birMonth)&&; 
         (curDay > birDay)))
      {
         error = UFLSetFormula(tempNode, "PAGE1.CURRENTYEAR.value -
            PAGE1.BIRTHYEAR.value");
         if (error != OK)
         {
            fprintf(stderr, "UFLSetFormula error %hd.\n", error);
            return(NOTOK);
         }
      }   
      else
      {
         error = UFLSetFormula(tempNode, "PAGE1.CURRENTYEAR.value -
            PAGE1.BIRTHYEAR.value - \"1\"");
         if (error != OK)
         {
            fprintf(stderr, "UFLSetFormula error %hd.\n", error);
            return(NOTOK);
         }
      }
      return(OK);
   }


Parent topic:
FormNodeP functions