tips:revmedia:v1i4a6

Comp

Published ByDateVersionKnowledge LevelKeywords
Sprezzatura Ltd01 AUG 19891.14+EXPERTCOMP, RTP21, BTREE.EXTRACT

In last month's RTPSeries, we bewailed the fact that RTP21 was not accessible to normal programmers, so this month we look at a system subroutine called COMP which has much of the functionality of RTP21 without requiring a system compiler to use.

Like all of the best routines, COMP is staggeringly simple to use. The multivalued array to be checked is put into @ANS and the comparison to be applied is passed as a parameter to the subroutine. There is no complicated coding system to remember, comparisons are sent as literals as with BTREE.EXTRACT or the query window. COMP then returns in @ANS a multivalued array of true/false flags corresponding to the comparisons requested. Thus if @ANS was set to 1 : @VM : 2 : @VM : 3 and COMP was called with a comparison of ">2", @ANS would be returned as 0 :@VM : 0 :@VM : 1.

The optimum use for this function is in determining how many of a multi-valued set meet certain criteria. As the answer is a true/false array, all we need to so is sum the array to find out how many correct answers we have. So if we had a field containing the ages of a subject's children, and we wanted to find out how many of them were over 18 we would use the following code

             @ANS = {CHILDRENS.AGE}
             CALL COMP(">18")
             NO.OVER = SUM(@ANS)
             CALL MSG("%1% children over 18","","",NO.OVER)

I have tested this routine with the standard operators (=, #, >, < , >=, <=,%,..., ], [, []) and it seems to work. More options may be available, further playing will tell!

(Volume 1, Issue 4, Page 4)

  • tips/revmedia/v1i4a6.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1