NumInstances

(Engine-Level Function)

Description: Returns the number of module instances currently running.
Returns: Numeric
Usage: Script or steady state.
Function Groups: Basic Module
Related to: GetInstance | Instance | CalledInstances
Format: NumInstances(Module)
Parameters:  
Module
Required. Any module or object value of the module to count.
Comments: This function is useful for counting both the number of active instances of the current module as well as the number of active instances of another module.

Example:

numThis = NumInstances(Self());
If ! Valid(numAnother);
[
  numAnother = NumInstances(FindVariable("Calculations", Self(),
  0, 1)); 
]

These statements count the number of active instances of the current module and the Calculations module. Notice that the script is necessary in the second case, not because of the NumInstances function, but because of the FindVariable function.

To determine whether a page is already open before calling ShowPage() use:

NumInstances(\PageModuleName)

... where PageModuleName is the name of the page module.