fboehlandt
Active Member
- Joined
- Sep 9, 2008
- Messages
- 334
Hi there,
I include the following code to create permutations of binary numbers. Just an adaptation of a similar code for letters. The permutations should be given in a n*k array:
The code works fine except when it comes to nDigits > 11. Here it just returns a #Value error in the cells and I don't know why. Is there an array size limi that is being exceeded? If so, is there a workaround? Any help is greatly appreciated. Also note that
is my quick and dirty solution to convert the text string into a 2-dimensional array.
p.s. for nDigits =12, for example, the above function returns the permutations for up to row 257 (or 3084 cells). The function is obviously entered as an arrray function. When the array is extended beyond 257 rows, I receive the #value error
I include the following code to create permutations of binary numbers. Just an adaptation of a similar code for letters. The permutations should be given in a n*k array:
Code:
Function PermNBinomial(nDigits As Long)
Dim MyArr As Variant, vArr As Variant, lRow As Long
ReDim vArr(1 To 2 ^ nDigits)
ReDim MyArr(1 To 2 ^ nDigits, 1 To nDigits)
PermNBinomial1 MyArr, vArr, nDigits, "", lRow, 1
PermNBinomial = MyArr
End Function
Sub PermNBinomial1(MyArr As Variant, vArr As Variant, ByVal lDigits As Long, ByVal s As String, lRow As Long, ByVal lind As Long)
Dim j As Long, s1 As String
For j = 1 To 2
s1 = IIf(lind > 1, s, "") & Chr(Asc("0") + j - 1)
If lind = lDigits Then
lRow = lRow + 1
vArr(lRow) = s1
For i = 1 To lDigits
MyArr(lRow, i) = CInt(Right(Left(vArr(lRow), i), 1))
Next i
Else
PermNBinomial1 MyArr, vArr, lDigits, s1, lRow, lind + 1
End If
Next j
End Sub
The code works fine except when it comes to nDigits > 11. Here it just returns a #Value error in the cells and I don't know why. Is there an array size limi that is being exceeded? If so, is there a workaround? Any help is greatly appreciated. Also note that
Code:
CInt(Right(Left(vArr(lRow), i), 1))
p.s. for nDigits =12, for example, the above function returns the permutations for up to row 257 (or 3084 cells). The function is obviously entered as an arrray function. When the array is extended beyond 257 rows, I receive the #value error
Last edited: