Shared Strategies


We use strategies across three products that are very similar. I’d like to share as much code as possible between all three strategies so that changes to one shared chart are reflected in the others. Is this limited to just shared subroutines or are there other mechanisms to share across strategies?


Hi FredA,

Welcome to the OptoForums! Glad you see you are finding ways to share code, well done–I’m guessing you have some programming experience in your background? And yes, that’s what subroutines are for (and how we build our “integration kits” which I sometimes describe as a library of commands).

However, you can also import/export charts, and import/export I/O Units, which is handy sometimes, and PAC Control will match the variables being imported.

Can you tell us a little more about your application, for example, which parts are similar between the different strategies?



Thanks for the quick reply Mary!
I’m new to OPTO, but have been a software engineer for 20+ years, and I’ve seen problems arise when code is copied between projects then fixed in only one of them. In our applications, we have complex charts that use Action blocks and scripts, and although a large number of charts are exactly the same between applications, some charts vary significantly, so I’d like to share on a chart by chart basis rather than merely subroutines. It sounds like I can isolate some functionality into subroutines for sharing, but for charts I will have to remember to import/export as changes are made.
I’ll look into the integration kits for examples of subroutines as libraries.


Just an FYI: You can go to Chart | View Print Instructions, save this to a file and run a diff on the two files if you need to find out where the differences are between two charts that are supposed to be the same.


Also note: before version 9.5, you could only go one subroutine deep. But now with 9.5 and better, where a sub can call a sub (no recursion allowed) etc, you have more options.

Can you move some of that chart logic into a sub, so the charts themselves have very little code (perhaps just a loop) besides calling subs?


If you are moving chart code to subroutines, be aware that there are some subroutine limitations on using pointers. Can’t create pointer tables in a subroutine for one, you have to pass them in from the chart. There are also assignment limitations to pointers - can’t assign subroutine variables to pointer tables.