Skip to Content
0
Former Member
Oct 05, 2009 at 01:41 PM

Need help in optimizing the formula

12 Views

I have a custom parameter naming {?param_field} where the user will enter values of employee id like "1","2","3","4".

In my record selection i need to check whether the first value is equal to the {employee.emp_id} db value and so on rather than using {employee.emp_id} in {?param_field}.

Solution is found but i need to optimize it.

I have created a formula array_count to split the parameter values and count the number of values given as input.

In the record selection i have written the below code.

Global NumberVar array_count;

Global stringvar array par;
redim par[500];

if (array_count = 1) then
(
 par[1] := replace(split({?param_empid}[1],",")[1],chr(34)," ");
{employee.emp_id} =  tonumber(totext(par[1]))
)
else if (array_count = 2) then
(   
par[1] := replace(split({?param_empid}[1],",")[1],chr(34)," ");        
par[2] := replace(split({?param_empid}[1],",")[2],chr(34)," ");
    (
	{employee.emp_id} = tonumber(totext(par[1])) or
	{employee.emp_id} = tonumber(totext(par[2]))
    )
)
else if (array_count = 3) then
(   
    par[1] := replace(split({?param_empid}[1],",")[1],chr(34)," ");        
    par[2] := replace(split({?param_empid}[1],",")[2],chr(34)," ");
    par[3] := replace(split({?param_empid}[1],",")[3],chr(34)," ");
        (
    	{employee.emp_id} = tonumber(totext(par[1])) or
    	{employee.emp_id} = tonumber(totext(par[2])) or
        {employee.emp_id} = tonumber(totext(par[3]))
        )
)

This works fine but i need to optimize the code. Pls let me know your suggestions and comments.