Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Add method, return type

Rob
2019-10-08
2019-10-09
  • Rob - 2019-10-08

    Hello everybody,
    I have a very basic/beginner question:
    When implementing a method, there is a field on the "Add Method" Window called "Return Type" (for BOOL, and other types)...I couldn't find at the Codesys Online Help further information about this and I'm not sure to understand when a method returns, let's say, an assigned Bool type to what variable...how do I assign a bool variable in the method to a return? or what is this exactly for? ...sorry for the dumb question, could someone please show me a simple example of a use case for this?

     
  • Anonymous - 2019-10-09

    Originally created by: scott_cunningham

    If you only want to return one variable, use the return type. To assign a value, do something like below. If you need to return multiple variables, use VAR_OUTPUT.

    Example will return 7 when you call the method.

    METHOD MyMethod : INT

    VAR
    Dummy : INT := 7;
    END_VAR

    MyMethod := Dummy;

     
  • Rob - 2019-10-09

    scott_cunningham hat geschrieben:
    MyMethod := Dummy;

    Thanks!! This was the part I was missing !!

     

Log in to post a comment.