Skip to main content

Summarization function

In the summarization function IDEA wants to know what statistics functions to use. When all are selected the code is as follows: task.StatisticsToInclude = SM_SUM + SM_MAX + SM_MIN + SM_AVERAGE + SM_VARIANCE + SM_STD_DEV
 
I created check boxes in a dialog menu so the user can select the statistics function they want to use. The check boxes are set as boolean, but i added a If function that when a statistic function is selected (example sum) a variable (sting) is set with SM_Sum and if not it is set to "". 
 
The problem i have is that the script first need to determine what functions are selected and then build the code line for the task.StatisticsToInclude line. How do I let IDEA build a line so that in front of every second statistic function a "+" is added?

Brian Element Thu, 08/30/2018 - 08:23

Hi Robert,

You can use something like this.  Each of the items such as SM_SUM, SM_MAX are actually integers that you can add together.  You could use the numbers also but you use the constants as it makes it easier to read.  So in this instance you just add them together and set the task.StatisticsToInclude to the result.  Here is an example, you would set task.StatisticsToInclude= iStatsToInclude:


Sub Main
	Dim bSum As Boolean
	Dim bMax As Boolean
	Dim bMin As Boolean
	Dim bAverage As Boolean
	Dim bVariance As Boolean
	Dim bStdDev As Boolean
	Dim iStatsToInclude As Integer

	bSum = True
	bMin = True
	bStdDev = True
	iStatsToInclude = 0
	
	If bSum Then
		iStatsToInclude = iStatsToInclude + SM_SUM 
	End If
	If bMax Then
		iStatsToInclude = iStatsToInclude + SM_MAX  
	End If
	If bMin Then
		iStatsToInclude = iStatsToInclude + SM_MIN  
	End If
	If bAverage Then
		iStatsToInclude = iStatsToInclude + SM_AVERAGE  
	End If
	If bVariance Then
		iStatsToInclude = iStatsToInclude + SM_VARIANCE  
	End If
	If bStdDev Then
		iStatsToInclude = iStatsToInclude + SM_STD_DEV 
	End If
	
	MsgBox iStatsToInclude

End Sub

Robert van den… Thu, 08/30/2018 - 10:11

In reply to by Brian Element

it works, thanks. For my knowlegde: IDEA knows every numeric combination to identify which functions it need to use? Because i thought it would only work with text as SM-SUM. And a more general question is there a book on how to learn to program this kind of language?

Brian Element Thu, 08/30/2018 - 14:17

In reply to by Robert van den…

IDEA doesn't know the combination but what you are actually doing is setting a bit in an 8 bit binary code.  It is a trick to use less memory to do things like this.  So SM_SUM is 2 (setting the first bit), SM_MAX is 4 (this sets the second bit), SM_MIN is 8 (setting the third bit) and so on.  So the code looks to see what bits have been set to decide which stats to use.  So the number six is represented by selected the first two bits.  The number four would only be the second bit and so on.  Hopefully that makes a bit of sense.  The only IDEAScripting book that is available the "Mastering IDEAScript the definitive guide"

Robert van den… Fri, 08/31/2018 - 03:11

In reply to by Brian Element

i get the idea, is it possible to convert the 8 bit binary code back to plain text/string? To present it to the user like "The next statistics functions are used: sum, avarage."

Robert van den… Mon, 09/03/2018 - 09:59

In reply to by Brian Element

i thought if you collect the selection by the user in bit code, then and after the script is finished you can show the user in text what he selected. Because with flat text if a option is not used it will create a blank in the message line. I first thought to make an array of it and then remove the blanks and  unbound it. But i can't get the remove blanks function get te work with that. So i thought this is maybe an easier method.