How to make a custom function in my rapid program?

Can I make myself a function the same way I make a procedure in RAPID programming? If yes then what is the proper syntax for it?

Here is an example of a simple function.

FUNC num abs_value(num value)

IF value<0 THEN

RETURN -value;

ELSE

RETURN value;

ENDIF

ENDFUNC

gr,

Richard

Here is an simple example.

FUNC num abs_value(num value)

IF value<0 THEN

RETURN -value;

ELSE

RETURN value;

ENDIF

ENDFUNC

gr,

Thanks, I didn’t declare the function type :wink:

Hi, Just wondering how can you make the custom functions global? Do you need to declare in a header file or something and include the header file in your main?

Regards
Kent

Hi,

all procedures, functions and data declarations are defined as global in a Task if the argument “LOCAL” is not used.

Examples for global declarations:

CONST num nMyNum:=1;

PROC MyProc()

FUNC num MyFunc()

Examples for local declarations in a module:

LOCAL CONST num nMyNum:=1;

LOCAL PROC MyProc()

LOCAL FUNC num MyFunc()

If you are using a persistant data declaration, you have the following possibilties

PERS num nMyNum:=0; (Persistant is defined as global for all tasks, in case of same declaration is available in the other tasks

LOCAL PERS num nMyNum:=0; (Persistant is only available in the module)

TASK PERS num nMyNum:=0; (Persistant is global in the current task)

Regards

Micky