use string for referencing to variable
in RobotStudio
Hey to all,
Sorry for this stupid question. I am really new to that stuff. First of all: YES, I tried to search the help, much more longer than a few minutes :-)
minimal example:
-------------------------------
!three position variables
CONST pos position_1 := [10, 10, 10];
CONST pos position_2 := [1, 1, 1];
VAR pos position_3;
!string containing variable names
CONST string positions := ["position_1","position_2"]
!want to assign position from string
position_3 := positions{2};
------------------------------
---> doesn't work, because "position{2}" is a string and not a position
I hope there is an easy solution :-)
thanks
RockOn
RockOn_232012-11-03 12:54:15
0
Comments
-
You will need to create a function that returns the data that the string identifies. Be sure to handle the error handler correctly for your application to avoid using "not found" data, etc. You can decide where to handle the error for error handling, either in the function itself or the calling part of the program... In its simplest form, you could replace your assignment with GetDataVal positions{2},position_3; - but this does not lend itself to handling any error(s) if you need too - or how to handle multiple "GetDataVal" Instrucitons in one routine for example...!three position variablesCONST pos position_1 := [10, 10, 10];CONST pos position_2 := [1, 1, 1];VAR pos position_3;!string containing variable namesCONST string positions{2} := ["position_1","position_2"];!want to assign position from string!position_3 := positions{2}; Error 101: Type error: Type mismatch of expected type pos and found type string instead, use:position_3:=fPOSbyName(positions{2});
!Check for valid return value here before usingTPWrite "pos "+positions{2}+":="pos:=position_3;FUNC pos fPOSbyName(string posName)VAR pos value:=[0,0,0];GetDataVal posName,value;return value;ERRORTPWrite "ERROR! " + posName + " NOT FOUND!";TryNext;ENDFUNCThomas H. Johnston
PACs Application Engineer0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings