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

help with User Defined Function

Hi

I want to code a UDF which comapres an array that contains "X" or empty values,with an array which contains only "X" and return a boolean array with boolean arguments (true/false)

I tried using the exisiting functions but I didnt find something relevant

Thx,Shai

Add comment
10|10000 characters needed characters exceeded

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 03, 2006 at 04:16 AM

    Hi Shai,

    if I understand your scenario correct you can do that easily with the existing functions. Just use

         Array  
                  equalS --> Result
    Constant[X] /

    Array is the list that contains your input values (X or empty), Result is your target value that will contain true or false. The function equalS will continue to compare the value of Array with the constant X.

    Regards,

    Claus

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 03, 2006 at 05:31 AM

    Hi,

    <i> return a boolean array with boolean arguments (true/false)</i>

    AFAIK, an User Defined Function can return only a STRING. It cannot return a Boolean Variable and also cannot return an Array.

    Regards,

    Bhavesh

    Add comment
    10|10000 characters needed characters exceeded

    • Func 1: public void ChkForX(String[] a,ResultList result,Container container){

      int flag = 0;

      int count = 0;

      for (int i = 0; i<a.length; i++)

      {

      if(a<i>equals("X"))

      {flag = 0; }

      else

      {flag = 1;

      count = count + 1;

      }

      }

      if(count > 0)

      {

      result.addValue("1");

      }

      else

      {result.addValue("0");

      }

      Func 2:

      public void ChkSpaces(String[] a,ResultList result,Container container){

      int flag = 0;

      int count = 0;

      for (int i = 0; i<a.length; i++)

      {

      if(a<i>equals(" "))

      {flag = 0; }

      else

      {flag = 1;

      count = count + 1;

      }

      }

      if(count > 0)

      {

      result.addValue("2");

      }

      else

      {result.addValue("3");

      }

      Kinda use both these functions with the same input then further build your logic ... but still i dont think you will get a array as output using UDF

  • Posted on Aug 03, 2006 at 02:15 PM

    As the guys have said, you won't get an boolean array from an UDF.

    The best you could get from an UFD is a string where each char is either 1 or 0, meaning true or false. Your input could also be a string with either X's or whitespaces.

    You could do it like:

    int i = 0;

    String output = "";

    while (i < input.length()) {

    if (input.charAt(i) == 'X') {

    output = output.concat("1");

    }

    else {

    output = output.concat("0");

    }

    i++;

    }

    return output;

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 03, 2006 at 02:51 PM

    Shai,

    you don't need an "array" of 'X'. You only need one constant with the value 'X'. The text function equalS will continue to compare the values provided by your array with the constant 'X' and create an output array of true/false accordingly.

    Regards,

    Claus

    Add comment
    10|10000 characters needed characters exceeded