Submitted by gregory on 2015/07/17 07:16
I have made my first successful use of column equations. However, when I have attempted to be a little bit more adventurous, I have failed.
 
I have defined in user code the following VBScript function:
 
function notYetDone (Done, NotDone) 'Returns true if done remains null and not notDone
notYetDone = isnull(Done) and not notDone
end function
 
Figure 1 I include the function notYetDone as part of a column equation on taskDuration
 
Figure 1 point 1 highlights the IQ system field taskDuration. This column is given the label Nb Days, as in the standard InfoQube sample IQ base.

Figure 1 point 2 shows the column equation now associated with that IQ system field. The full text is: mysum(notYetDone (Done, NotDone)).
 
 
 
Figure 2 The column equation is no longer working
 
Figure 2 point 1 shows that the parent total number of days is now blank. If I remove my column equation in favour of a simple use of MySum, a figure of 50.5 days is calculated and displayed.

Can anyone suggest what I am doing wrong and how to correct it? Many thanks.
 

Comments

I don't think you can have a function inside another fonction...
Simply create a new mySum function will all parameters...
 
Perhaps our "resident expert", Armando, can comment on this... 
 

gregory

2015/07/17 14:29

In reply to by Pierre_Admin

Hi Pierre.

What you you suggest sounds plausible, but I can't get it to work.

So I define a new function:

Function sumNotYetDone(Done, NotDone, x)  ' Calculates the sum of the array x if done remains null and not notDone
  dim d, i, mySum

  d=ubound(x)
  for i=0 to d
    if isnull(Done) and not notDone then mySum = mySum+NZ(x(i))
  next
  sumNotYetDone = mySum

End Function

To use that - and this is where I am not quite certain that I am doing the right thing - I set a column equation on TaskDuration which is:

sumNotYetDone (Done, NotDone, TaskDuration))

It is that third parameter TaskDuration which has me worried. This has to be the name of an array...

Do you have any further suggestions? Or Armando? Or any other benevolent contributor?
 
 
Mark GREGORY, Redon, France - GMT +1/+2; EST +6

Pierre_Admin

2015/07/17 15:41

In reply to by gregory

Hi Mark,
 
3 things to remember:
  1. All parameters to the column equation are arrays, so Done and NotDone in your equation are also arrays, not just x
    Your equation should then be: if isnull(Done(i)) and not notDone(i) then mySum = mySum+NZ(x(i))
  2. Don't forget to [ ] enclose all fields for proper parsing
  3. Since this is a column equation, each array element represents an item, so no need to worry about TaskDuration not being an array in IQ, it becomes an array in your user code
HTH !
 
Pierre_Admin
 

gregory

2015/07/17 17:55

In reply to by Pierre_Admin

Thanks Pierre, BUT...
 
1. Thank you for the explanation!
2. Whoops! I should know better...
3. Thank you for the explanation!
 
Equation now reads:
 
sumNotYetDone ([Done], [NotDone], [TaskDuration])
 
... BUT nb days for the parent remains stubbornly blank.
 
Mark GREGORY, Redon, France - GMT +1/+2; EST +6

gregory

2015/07/18 06:27

In reply to by Pierre_Admin

There was an error in the work that I have presented so far. A more careful reading of the manual makes it clear that there is no need to include the name of the field for which the hierarchy equation is being defined as an explicit parameter in the definition of the field. Thus, where above I suggested:

sumNotYetDone (Done, NotDone, TaskDuration))

All that is actually needed is:

sumNotYetDone (Done, NotDone))

The third parameter is redundant and should be omitted.

However, as I posted yesterday, even with this change the user-defined hierarchy equation yields no result.

I have investigated further. Recall that VBScript can appear either in system code, user code or this database. Provided that the hierarchy equation appears in system code, it works. Since system code is now read-only, I cannot put my own code there. Any code which I include as a hierarchy equation in either user code or this database does not appear to be effective. So, for example, I established the very simple formula zSum based on a copy of the code of the system function sum:

Function zSum(x)  ' Calculates the sum of the array x
  dim d, i

  d=ubound(x)
  for i=0 to d
    zSum=zSum+NZ(x(i))
  next
end Function

Sum continues to work; zSum does not.
 
Mark GREGORY, Redon, France - GMT +1/+2; EST +6