On Wed, 6 Aug 2003 23:04:45 -0400, "Jim Hubbard"

<ji**********@hotmail.com> wrote:

Does anyone have any code for doing combinations in VB.net or visual

basic ? I'd like to

be able to get an array of combinations (not permutations) of words from a

base group of words while specifying the number of unique words to be used

in the result set.

For instance if I have the set {cat dog fish snake} I'd like to be able

to get back a result array of all possible combinations (not permutations)

of X number of words from my base set. For example, all possible

combinations of any 3 words from the base set above would be :

{cat dog fish}

{cat dog snake}

{cat fish snake}

{dog fish snake}

Something like this could do the trick :-

Option Explicit: DefObj A-Z

' Combinations : J French 7th Aug 03

Private Sub Command1_Click()

Dim Dest$

Call LS_Combine(3, "", "ABCD", Dest$)

Me.Print Dest$

End Sub

Private Sub LS_Combine(SampleSize%, RootIn$, FullSetIn$, Dest$)

Dim L9%, Root$

' --- At bottom - take result and exit

If SampleSize = 0 Then

Dest$ = Dest$ + RootIn$ + vbCrLf

Exit Sub

End If

' --- For each possible Start Letter

For L9 = 1 To Len(FullSetIn$) - SampleSize + 1

' --- Build Root

Root$ = RootIn$ + Mid$(FullSetIn$, L9, 1)

' --- Handle Residue

Call LS_Combine(SampleSize% - 1, _

Root$, _

Mid$(FullSetIn$, L9 + 1), _

Dest$)

Next

End Sub