IF statement on a field

IF statement on a field

I have to give a value to a field (let say FIELD1) according the following criteria where FIELDXs are type float

if (FIELD2  !=  0)
{
    FIELD1 = FIELD2;
}
else if (FIELD3  !=  0)
{
    FIELD1 = FIELD3;
}
else if (FIELD4  !=  0)
{
    FiELD1 = FIELD4;
}
else
{
    FIELD1 = FIELD5;
}


where I should put it. I tried on Form edit/validate ! form edit/Load but seems not working. the same on the Field /input ! field/validate
find in the attachment the right if statement applied.

Thx