RobotStudio event

RAPID: use string as argument name


I'm looking for a way to produce the reverse of ArgName(anytype)
Rather than getting the name of an argument as a string, I'd like to use a string as the name of an argument.

VAR num MyArg1 := 5;
VAR string Arg_string := "MyArg1";

I'd like to be able to use the value of Arg_string within code to call up the value of MyArg1, similar to how it's possible to call a procedure named by a string by surrounding the string argument name with %

VAR string CallProc := "SomeProcedure";
%CallProc%

This code would execute the procedure named "SomeProcedure"

I'm trying to do the same thing with the names of variables.

Alyssa Wells2013-02-28 18:41:00

Comments



  • To my knowledge, late binding is available for procedure calls only, see the RAPID Overview manual. Perhaps you can workaround it by creating procedures that act as variables, see my example below

    [CODE]MODULE MyModule
        VAR num myarg1:=0;

        PROC ProcMyArg1(INOUT num outparameter)
            outparameter:=5;
        ENDPROC

        PROC main()
            VAR string CallProc:="ProcMyArg1";
            %CallProc% myarg1;
            TPWrite "The value of " + CallProc + " is " + NumToStr(myarg1,0);
        ENDPROC
    ENDMODULE[/CODE]

    Output:
    image






    Henrik Berlin2013-03-01 07:48:51
    Henrik Berlin
    ABB
  • osku
    osku ✭✭
    Hi
     

    I think GetDataVal and SetDataVal instructions are what you are looking for. With these instructions you can get and set the value of the variable based on the name given in the string.

     

    -Osku
  • Thanks osku, exactly what i was looking for.