CREATE CURSOR crsAmounts (Amount I) &&Fake Data
FOR i = 1 TO 10 && Fill up cursor with some values
INSERT INTO crsAmounts (Amount) VALUES (i)
ENDFOR
CLEAR
PUBLIC lnTotal && Public so we can see the value after the run
PUBLIC ARRAY aryAmounts(1,2) && Public so we can look at the array after code has run
aryAmounts = ""
lnTotal = 0
SELECT amount FROM crsAmounts INTO ARRAY aryGroup
FOR i = 2 TO 10 &&assuming that at least 2 items have to be chosen from the set, if not then make it a 1 or whatever
GetCombinations(i,@aryGroup)
ENDFOR
*!* Now go look at the array aryAmounts in the locals debug window
*************************
PROCEDURE GetCombinations(tcSize, tcSet)
*************************
LOCAL lnMembers, lnCounter, lnTemp
lnMembers = ALEN(tcSet)
DIMENSION aryIndice(lnMembers)
aryIndice = 0
DO WHILE .T.
IF aryIndice(1) < 1
lnCounter = 1
FOR lnCounter = 1 TO tcSize
aryIndice(lnCounter) = lnCounter
ENDFOR
SaveAmount(lnMembers, @tcSet, @aryIndice)
LOOP
ELSE
lnCounter = tcSize &&- 1
DO WHILE lnCounter >= 1 AND aryIndice(lnCounter) >= (lnMembers - tcSize + lnCounter)
lnCounter = lnCounter - 1
ENDDO
IF(lnCounter >= 1)
aryIndice(lnCounter) = aryIndice(lnCounter) + 1
lnTemp = lnCounter
DO WHILE lnTemp < tcSize
lnTemp = lnTemp + 1
aryIndice(lnTemp) = aryIndice(lnTemp-1) + 1
ENDDO
SaveAmount(lnMembers, @tcSet, @aryIndice)
LOOP
ELSE
EXIT
ENDIF
ENDIF
ENDDO
ENDPROC
*************************
Procedure SaveAmount(tcMembers, tcSet, tcIndice)
*************************
LOCAL lnCounter, lcString, lnAmountSum
lnTotal = lnTotal + 1
lcString = ""
lnAmountSum = 0
FOR lnCounter = 1 TO tcMembers
IF tcIndice(lnCounter) != 0
lnAmountSum = lnAmountSum + tcSet(tcIndice(lnCounter))
lcString = lcString + TRANSFORM(tcSet(tcIndice(lnCounter))) + " + "
ENDIF
ENDFOR
IF !EMPTY(aryAmounts(ALEN(aryAmounts)))
DIMENSION aryAmounts(ALEN(aryAmounts,1) + 1,2)
ENDIF
aryAmounts(ALEN(aryAmounts,1),1) = lnAmountSum
aryAmounts(ALEN(aryAmounts,1),2) = Left(lcString,LEN(lcString) - 3)
?Left(lcString,LEN(lcString) - 3) + " = " + TRANSFORM(lnAmountSum) && So you can see it processing
ENDPROC