Val3: no way to create a function to return a value ?

  • I am not new to programming but am to Val3. I hope I am just missing something in that I can't return a value from a call or create a function in the language. So, I can only call programs and set a value in that to a global variable to be accessed after the program call ? eg. I'd like to return a bool for a home check:


    if check_home() != true

    // fault handling

    endIf


    vs.

    // check_home internally sets bAtHome to true if near home position

    call check_home()


    if bAtHome != true

    // fault handling

    endIf


    Am I missing something ? Returning a value seems basic to me and Val3 seems to have common language constructs. I hope it is my inexperience with the language that I'm missing something.


    I see a way to create an application and package as a "library", but no mechanism for return values either. Is there a SDK to extend the language or create drivers/plugins ?


    Thanks for any info !

  • Hi,


    I do not know too much about val3. But I think knowing a little bit about procedures and functions.


    How did you programmed your function?


    in val3 procedures start with

    procedure and name of procedure and maybe a couple of parameter

    to call the procedure you would write

    call name of procedure (see your example).


    In order to create a funtion with return code you would write

    bool check_home()


    In some languages you also could call the function like a procedure if you do not care about the return code


    regards


    MOM

  • Hello prisonprime,


    in VAL3, if you don't want to use the way you wrote with global variables, you have to use parameters by reference in order to have a return value.


    The programm should have a bool parameter by reference: check_home(bool& x_bAtHome)

    Then you can call the sub programm with the parameter as a return value.

    call check_home(bAtHome)

    The difference between theory and practice is greater in practice than in theory.

Advertising from our partners