Pass Table Elements as Variables into Subrotines

Can I pass table elements as variables (“passed by reference” parameters) into subroutines?
I want to pass a table element, have the subroutine update it, and then send it back to the same table.

I’m having trouble making this work and results in having to make unique temporary tables to pass variables back and forth in each chart that I call the subroutine… which mostly defeats the purpose of using it.

Thanks
Eric

You have to pass the entire table if you want to modify an element in that table. The other option is to pass the table elements value to the subroutine, and then write it to the table after the subroutine returns.

Edit: You can also pass the table as a parameter along with the index that you want to have modified.

1 Like

Oops, well good to know. I think passing the entire table should work pretty well for me. I’m passing a few tables but the index will be the same for all of them so that makes it easy.

Thank you!

Follow up. Could I pass a pointer table, filled with references to other tables, to a subroutine along with an index variable I want to work on.

Then in the subroutine:

  • Call an element of the pointer table
  • De-reference it to access the original table
  • Then, using the index, access the element I want to modify
  • make my changes and have the element updated.

I feel like this would not be possible because but I want to make sure.

Thanks again

Yes you can do all of the above.

1 Like