cancel
Showing results for 
Search instead for 
Did you mean: 

Function or Subroutine

Right now, I improvise calling subroutines by creating an invisible button with Onselect code and then invoking it with Select(myButton). This is handy when there are little pieces of code I use repitiously on the same screen. I then have a local variable that I assign a value to within the button. For example,

 

[myButton: OnSelect]

  UpdateContext({localVariable_Result: whatever-my-calculation-is  *  localVariable_functionArgumentValue1 * localVariable_functionArgumentValue2 * localVariable_functionArgumentValue3)});

 

  If(localVariable_Result=x,
    UpdateContext({localVariable_functionReturnValue:xx}),
  If(localVariable_Result=y,

    UpdateContext({localVariable_functionReturnValue:yy}),
  If(localVariable_Result=z,

    UpdateContext({localVariable_functionReturnValue:zz})
  ,
    UpdateContext(localVariable_functionReturnValue:Blank())
  )))

 

[Calling Object: OnSelect]
  UpdateContext({localVariable_functionArgumentValue1: "Test"});

  UpdateContext({localVariable_functionArgumentValue2: "Test2"});

  UpdateContext({localVariable_functionArgumentValue3: "Test3"})

  Select(myButton)

 

[Hypothetical TextBox: Text]

  functionReturnValue

 

 

 

So the functionality is already there, albeit in a duct-tape sort of way. It would be nice if there was a "function" object which is invisible by nature. The function object would have an .Argument and .ReturnValue property that returns an object and a "Return" instruction to set the value of the .ReturnValue. So instead of the example above, I would do something like this with a function object:

 

 

 

[myFunction Object]

  UpdateContext({localVariable_Result: whatever-my-calculation-is  *  FirstN(myFunction.Argument,1) * FirstN(myFunction.Argument, 2) * FirstN(myFunction.Argument, 3)});

  If(localVariable_Result=x,
    Return(xx)
  If(localVariable_Result=y,

    Return(yy)
  If(localVariable_Result=z,

    Return(zz)
  ,
    UpdateContext(functionReturnValue:Blank())
  )))

 

[Calling Object: OnSelect]

  'Invocation no longer needed'

 

[Hypothetical TextBox: Text]

  myFunction("test", "test2", "test3")

Status: New