Create your own SUBIX
Posted: Tue Jul 09, 2013 2:16 pm
I got fed up with not having a Subix function, so I ended up hardcoding one myself. Saves me a lot of time and thought.
This function will return the first instance of the element within the subset. You could search for the last instance by reversing the loop, or include an additional counter to count for the Nth instance in the subset.
This function will return the first instance of the element within the subset. You could search for the last instance by reversing the loop, or include an additional counter to count for the Nth instance in the subset.
Code: Select all
Parameters:
pDim - A valid dimension name.
pSubset - A valid subset name in pDim.
pElement - The name of an element within the dimension.
Code: Select all
## SUBIX ######################################################
## Intended Functionality: SUBIX(dimension, subset, element)
## Usage: ExecuteProcess('SUBIX', 'pDim', DIMENSION, 'pSubset', SUBSET, 'pElement', ELEMENT)
## SUBIX stores the index number of an element within a subset in the global variable 'gSubixReturn'.
## If the element is not found within the subset, gSubixReturn is set to -1.
##
## Before calling, be sure to include the line 'NumericGlobalVariable('gSubixReturn');' in the parent process.
################################################################
NumericGlobalVariable('gSubixReturn');
i = 1;
nMax = SubsetGetSize(pDim, pSubset);
gSubixReturn = -1;
WHILE(i <= nMax);
IF( SubsetGetElementName(pDim, pSubset, i) @= pElement);
gSubixReturn = i;
i = nMax;
ENDIF;
i = i + 1;
END;