plctwincatst

How to assign the value to be returned by a method?


I have a method which I want to be returning a value. The declaration is clear to me. But how do I assign the value to be returned inside the method implementation?

I can only think of creating an output variable and use that to propagate the value to the caller. But that is definitely not how I would expect a return value to work:

METHOD M_MyMethod : BOOL
VAR_OUT
    bReturnVal : BOOL;
END_VAR
// Do some method things here.
// Then assign the return value.
bReturnVal := bWhatever;

Solution

  • The solution is simple:

    M_MyMethod := bWhatever;
    

    Using VAR_OUT is also usefull, if you need to return more than one value and don't want to create dedicated type :)