Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hard to do - aritmethic combination.
Message
From
29/06/2002 09:08:33
 
 
To
28/06/2002 14:11:03
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00673403
Message ID:
00673604
Views:
20
This message has been marked as the solution to the initial question of the thread.
>Exactly. Thanks for your reply.

So...
It may be "hard to do" if you think relationally - better think recursive!
Lets define a single iteration for retrieving the combinations that contain value from record 1.
They will be:
1;
1,2;
1,2,3;
1,2,3,4;
...
1,2,3,...,n

The number of these combinations is exactly n. Next step is to define the iteration for retrieving combinations that contain value of record 2 (except those containing value of record 1):
2;
2,3;
2,3,4;
2,3,4,5;
...
2,3,4,...,n

The number of these combinations is exactly (n-1)...

So if we summarize the above we will get the following algorith (draft program):
PROCEDURE CalculateSums
LPARAMETERS vnCurrentRecNo
Local lnaSums, lnIndex, lnCurRecNo
IF EMPTY(vnCurrentRecNo) Then
	vnCurrentRecNo = 1
ENDIF

Dimension lnaSums(RECCOUNT()-vnCurrentRecNo+1)

lnIndex = 1
Locate RECORD (vnCurrentRecNo)

lnaSums(1)=Test.DataField

SCAN for recno()>vnCurrentRecNo
	lnIndex = lnIndex+1
	lnaSums(lnIndex) = lnaSums(lnIndex-1) + Test.DataField
ENDSCAN
IF vnCurrentRecNo<RECCOUNT() THEN
	CalculateSums(vnCurrentRecNo+1)
ENDIF
* Here you can add a code to populate the array lnaSums to a cursor
ENDPROC
HTH
Zlatin Zlatev,
MCSD (VS6)

Make solutions, not programs!

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform