Expand my Community achievements bar.

How to make a function call.

Avatar

Former Community Member

Hello ,

I tried to call the function in Form Calc but there are some error. can any one say the right syntax to be used.Please find example what i tried

if(x eq 1) then

values()

endif

func values()

xfa.host.messageBox("test")

endfunc

Kindly any one let me know where i went wrong

Best Regards,

Rakesh

8 Replies

Avatar

Former Community Member

Hello ,

Can any one answer this?

Reagrds,

rakesh

Avatar

Level 10

Hi,

I am going out on a limb here. I have always used javascript for functions and while I am not sure if it will work in Formcalc, the following will work in Javascript:

if (this.rawValue == "1")

{

     values();

}

function values()

{

     xfa.host.messageBox("test");

} // end function

Hope that helps,
Niall

Avatar

Former Community Member

I do not believe that formCalc has support for functions.

Paul

Avatar

Former Community Member

Hello Paul / Nail ,

We have a Keyword for functions in Form calc like FUNC and ENDFUNC. So i feel we can use this but i am not sure about the syntax and i didt find any information in Help too.

Could you please search in your library wheather is there any Info or not.

Thank you for taking care,

Regards,

Rakesh

Avatar

Level 10

Hi Rakesh,

If you look at page 966 of the XFA specification (http://partners.adobe.com/public/developer/xml/index_arch.html#xfa_28), then you will see how to decalre and call a function in FormCalc:

func MyFunction(param1) do param1*param1 endfunc // Declares a function

MyFunction(3) //Invokes the function, which returns 9

It looks like your previous FormCalc function was missing the "do" call.

Bear in mind that if you start putting functions in script objects, you will have to revert to Javascript.

Good luck,

Niall

Avatar

Former Community Member

Hello Niall,

I could not get the syntax for the function that calls without parameters in form calc . i tried few scenarios but i am unsucessfull . could you help me here?

Thank You,

Best Regards,

Rakesh

Avatar

Level 10

Hi Rakesh,

It looks like in FormCalc you need to declare the function strictly before you call it. The attached example has both a Javascript function and a Formcalc function and while they both do the same thing (based on your original example) the Formcalc function is declared first.

Hope that helps,

Niall

Avatar

Former Community Member

Niall is right. The function must be declared before it can be used. A common practice is to put it on an Initialization event so it is available after that fires. The script object cannot be used as that is for Javascript only.

Paul