Quantcast
Channel: DIAdem topics
Viewing all articles
Browse latest Browse all 3196

ScriptInclude vs ScriptStart vs Sub Procedure vs etc, etc

$
0
0

Hi,

 

Could I ask for some help on determining when is best to use each of the various ways of arranging code into separate repeatedly used chunks?

 

My problem is partly due to not fully understanding this help page: https://zone.ni.com/reference/en-XX/help/370858P-01/comoff/scriptinclude/ or the equivalent one for ScriptStart. The comparison table at the bottom doesn't provide much clarity for me.

 

Essentially, I use a collection of scripts for analysing data from different tests. Whilst there's a lot of re-used code, I prefer to keep the code for each test separate from all the others. However, within each test there is still repeated code so it makes sense to put this into a suitable format for repeated use.

 

Part of my struggle is to understand the scope of variables in relation to ScriptInclude and ScriptStart. For example, one of my pieces of processing code needs to repeatedly call another chunk of code, which to date has been stored in a separate script. This separate script will produce results stored in variables that are needed later in the calling script. At the moment, these variables are declared at the top of the separate script.

 

Because of that last point, I thought that it was correct to use ScriptInclude so that the main script would 'see' the results variables. However, when I call the separate script for the second time using ScriptInclude nothing happens - the script doesn't run. Noting that the above help page says you should call ScriptInclude only once (why?), I changed my code to use ScriptStart for all subsequent calls after the first one. Following this, the main script fails after the second call of the separate script because a further script called later on doesn't 'see' the variables produced, presumably because I'm calling that later script with ScriptStart. However, I can't call that later script with ScriptInclude because it's been called once before.

 

What about sub procedures? Should I consider using them instead? This would make a neat single script with all the code in one place but it would be very long and harder to navigate.

 

So, I'd be grateful for a lay mans guide to understanding the principal benefits to ScriptInclude and ScriptStart (lay terms are important!), and some guidance on where I should be declaring the variables I use.

 

Many thanks, Simon.


Viewing all articles
Browse latest Browse all 3196

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>