Imagine having a number of factors (e.g. X,Y,Z) each having a set of values. As an example:

X1,X2,X3,X4 (factor 1 having 4 values)

Y1,Y2 (factor 2 having 2 values)

Z1,Z2,Z3 (factor 3 having 3 values)

This means we can have 4 x 2 x 3 = 24 different combinations. To give the first 6:

X1,Y1,Z1

X1,Y2,Z1

X1,Y1,Z2

X1,Y2,Z2

X1,Y1,Z3

X1,Y2,Z3 etc.etc.

Also Z1,X1,Y1 is regarded the same as X1,Y1,Z1 thus I am looking for unique combinations (I think that this is called 'no permutations')

Now, I tried to devise a generic algorithm that creates the full design set. So the number of Factors and Values is differntly every time. It seemed simple at first glance, but I can't get a grip on it. There's plenty of (statistical and scientific) background material on the subject, but I cannot find a practical example anywhere ...

Can anyone give me a start or a link to a good example?

'set n to the nubmer of facors

'and cardinality(i) to the number of values for the i-th factor

'e.g. n=4 with values 3,2,4,2

Dim n As Integer =4

Dim cardinality(4) As Integer

cardinality(0) = 3

cardinality(1) = 2

cardinality(2) = 4

cardinality(3) = 2

'generate combintions

Dim factors(n) As Integer

Dim i As Integer

Dim c As Integer

Dim msg As String

Dim carry As Boolean

For i = 0 To n - 1

factors(i) = 0

Next

Do

c = c + 1 'count combinations

'print combination

msg = "Combination " & c & ": "

For i = 0 To n - 1

msg = msg & factors(i) & " "

Next

MsgBox(msg)

'calculate next combination

i = 0

Do

factors(i) = factors(i) + 1

carry = factors(i) = cardinality(i)

If carry Then

factors(i) = 0

i = i + 1

End If

Loop While carry And i < n

Loop While Not carry