Passing unlimited number of arguments in ProcCall
JohnG
✭
This question isn't a show stopper for me at all. I have what I'm looking to do coded in a different way right now, just could be a lot cleaner if what I'm looking to do is possible. Is there a way to create a procedure without a predefined set of arguments?
such as in Python:
def ProcToCall (**args):
pass
One workaround I know I can do is predefine a larger list of optional arguments like below, but wouldn't be ideal for what I'm trying to achieve.
PROC ProcToCall (\VAR num Arg1, \VAR num Arg2.......)
IF Present(Arg1) THEN
!Do something
ENDIF
IF Present(Arg2) THEN
!Do something
ENDIF
.......
Thanks in advance.
such as in Python:
def ProcToCall (**args):
pass
One workaround I know I can do is predefine a larger list of optional arguments like below, but wouldn't be ideal for what I'm trying to achieve.
PROC ProcToCall (\VAR num Arg1, \VAR num Arg2.......)
IF Present(Arg1) THEN
!Do something
ENDIF
IF Present(Arg2) THEN
!Do something
ENDIF
.......
Thanks in advance.
Tagged:
0
Comments
-
Hello,you could pass an array that contains your required parameters.If you define the array directly in the routine call, you can pass as many parameters as you want without having to create an array as a variable previously.Attached is an example:
PROC TEST1() ProcToCall; ProcToCall\Args:=[1]; ProcToCall\Args:=[1,2,4]; ENDPROC PROC ProcToCall(\num Args{*}) VAR num nDim; !Get the number of parameters IF Present(Args) THEN nDim:=Dim(Args,1); IF Present(Args) AND nDim>=1 THEN TPWrite "Arg1: "\num:=Args{1}; ENDIF IF Present(Args) AND nDim>=2 THEN TPWrite "Arg2: "\num:=Args{2}; ENDIF ENDIF ENDPROC<br>
1 -
This is exactly what I was looking for. Thanks!0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings