Function

Implementing DECODE, IIF Functions

Let us take a look at how to replace and return values according to conditions.

For DECODE, specify the value as follows. This is an example that returns the corresponding weekday value according to the value transmitted as DATA. The big difference is that you can throw necessary conditions as parameters rather than setting conditional expressions within the function. It is similar to using the Switch statement.

decode(DATA, '0', 'SUN', '1', 'MON', '2', 'TUE', '3', 'WED', '4', 'THU', '5', 'FRI', '6', 'SAT', 'OTHERS');

For IIF, specify the value as shown below. Transmit the condition itself to be true and receive the result accordingly.

iif(DATA=='Y', 'Yes', 'No')

Example

If you enter a number from 0 to 6 in the first Edit component, then the corresponding day of the week is returned. The second Edit component returns 'No' if there is no value, and 'Yes' if there is a value.

sample_function_01.xfdl

Core features used in the example

arguments

Processes the parameters transmitted when calling the function as an array. In the case of the decode function, the number of arguments transmitted is not fixed, so you can check the number of arguments transmitted by using the arguments property.

How to implement an example

1

Configuring Form Screen

Place the Edit component and the Button component. Among Edit components, for the component that shows the result value, set the enable property value to false.

2

Writing Button Component Event Function

In the example, only the first parameter value is input from the Edit component and the remaining values are specified in advance.

this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	this.Edit02.set_value(this.fn_decode(this.Edit00.value, '0', 'SUN', '1', 'MON', '2', 'TUE', '3', 'WED', '4', 'THU', '5', 'FRI', '6', 'SAT', 'OTHERS'));
};

this.Button01_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	this.Edit03.set_value(this.fn_iif(this.Edit01.value, 'Yes', 'No'));
};

3

Writing fn_decode Function

Check the parameters transmitted using the arguments property. If it is entered as an even number, it means that there is a default value in addition to the value specified in the conditional expression. In the example above, the default value of 'OTHERS' was specified. Then, find and return the value corresponding to the given condition by using the iteration statement.

this.fn_decode = function()
{
    var sRtnValue = null;
    var arrArgument = this.fn_decode.arguments;
    var sValue = arrArgument[0];
    var bIsDefault = false;
    var nCount = 0;
	
    if ((arrArgument.length % 2) == 0) 
    {
        nCount = arrArgument.length - 1;
        bIsDefault = true;
    } 
    else 
    {
        nCount = arrArgument.length;
        bIsDefault = false;
    }
	
    for (var i = 1; i < nCount; i+=2) 
    {
        if(sValue == arrArgument[i]) 
        {
            sRtnValue = arrArgument[i+1];
            i = nCount;
        }
    }
	
    if (sRtnValue == null && bIsDefault==true) 
    {
        sRtnValue = arrArgument[arrArgument.length-1];
    }
	
    return sRtnValue;
};

4

Writing fn_iif Function

Checking the parameters transmitted using the arguments property is the same as the fn_decode function. However, since it receives 3 values, it processes a simple function that returns the second value if the first value is true, and returns the third value otherwise.

this.fn_iif = function()
{
    var arrArgument = this.fn_iif.arguments;
	
    if (arrArgument[0]) 
    {
		return arrArgument[1];
    } 
    else 
    {
        return arrArgument[2];
    }
};

5

Checking with QuickView

Run it with QuickView (Ctrl + F6) and check while entering values.