LOCAL llContinue, llAdd, llCarry, X, lnSum, lcValues #DEFINE nMASK 1 #DEFINE nVALUE 2 #DEFINE nVALUES 10 #DEFINE nTARGET 15 DIMENSION aCombo [nVALUES, 2] aCombo [1, nValue] = 3 aCombo [2, nValue] = 6 aCombo [3, nValue] = 7 aCombo [4, nValue] = 2 aCombo [5, nValue] = 1 aCombo [6, nValue] = 4 aCombo [7, nValue] = 13 aCombo [8, nValue] = 12 aCombo [9, nValue] = 9 aCombo [10, nValue] = 10 llContinue = .T. DO WHILE llContinue * Test lnSum = 0 FOR X = 1 TO nVALUES lnSum = lnSum ; + IIF (aCombo[X, nMask],; aCombo[X, nValue], 0) ENDFOR * Output lcValues = "" IF lnSum = nTARGET FOR X = 1 TO nVALUES lcValues = lcValues ; + IIF (aCombo[X, nMask], ; TRANSFORM (aCombo[X, nValue]) + ",", ; "") ENDFOR lcValues = LEFT (lcValues, LEN (lcValues) - 1) WAIT WINDOW lcValues ENDIF * Increment mask llAdd = .T. FOR X = 1 TO nVALUES && If the current value is TRUE (a 1) and we're adding, set llCarry to .T. llCarry = llAdd AND aCombo [X, nMask] && Assign the current value using an XOR function (not in VFP for logicals) && Truth table: && aCombo llAdd aCombo next state && .F. .F. .F. && .F. .T. .T. && .T. .F. .T. && .T. .T. .F. value is carried to next digit aCombo [X, nMask] = (aCombo [X, nMask] OR llAdd) AND NOT (aCombo [X, nMask] AND llAdd) && Setup for next iteration of loop llAdd = llCarry ENDFOR llContinue = NOT llCarry && If we're carrying on the last digit, we're done ENDDOEnjoy!