SUB , array, variables ? HELP !

• Question

• i try to find a way to do this , for example:

For X = 1 to 3

BAR[x]()

EndFor

Sub BAR [1]

do something

endsub

Sub BAR [2]

endsub

Sub BAR [3]

call my boss

endsub

Tuesday, May 3, 2016 8:11 PM

• Or...

You can call subroutines from other subroutines.   :-)

```task = 1

EndIf
EndSub

'stuff..
EndSub

'stuff..
EndSub

'stuff..
EndSub```

• Proposed as answer by Wednesday, May 4, 2016 5:28 PM
• Marked as answer by Wednesday, May 18, 2016 5:52 PM
Wednesday, May 4, 2016 3:44 PM

All replies

• ```For X = 1 to 3
BAR()
EndFor

Sub BAR
If (x=1) then
TextWindow.WriteLine("Do x="+x)
ElseIf (x=2) then
TextWindow.WriteLine("Do x="+x)
ElseIf (x=3) then
TextWindow.WriteLine("Do x="+x)
EndIf
EndSub```

Or

```For x = 1 to 3
Stack.PushValue("Args",x)
BAR()
EndFor

Sub BAR
arg = Stack.PopValue("Args")
If (arg=1) then
TextWindow.WriteLine("Do arg="+arg)
ElseIf (arg=2) then
TextWindow.WriteLine("Do arg="+arg)
ElseIf (arg=3) then
TextWindow.WriteLine("Do arg="+arg)
EndIf
EndSub```

Or, using extension function with a return value

```args = ""
For x = 1 to 3
result = LDCall.Function("BAR",x)
TextWindow.WriteLine(result)
EndFor

Sub BAR
If (args[1]=1) then
TextWindow.WriteLine("Do arg="+args[1])
return = "Result1"
ElseIf (args[1]=2) then
TextWindow.WriteLine("Do arg="+args[1])
return = "Result2"
ElseIf (args[1]=3) then
TextWindow.WriteLine("Do arg="+args[1])
return = "Result3"
EndIf
EndSub```

• Proposed as answer by Wednesday, May 4, 2016 5:28 PM
Tuesday, May 3, 2016 8:24 PM
• Fantastic ! solution #1

i will applied to my Moonlight Sonata program, :) thanks !

Tuesday, May 3, 2016 9:19 PM
• Or...

You can call subroutines from other subroutines.   :-)

```task = 1

EndIf
EndSub

'stuff..
EndSub

'stuff..
EndSub

'stuff..
EndSub```

• Proposed as answer by Wednesday, May 4, 2016 5:28 PM
• Marked as answer by Wednesday, May 18, 2016 5:52 PM
Wednesday, May 4, 2016 3:44 PM
• great solution to Coding Cat, i like it !

thanks :)

Wednesday, May 4, 2016 4:59 PM