Hi,
I want to optimize my code to list alll possible iterations of an input based of None, 0 and 1 where None is either 0 or 1.
I have a dirty trick with a random function to generate 0 or 1, but I would like to code the cleaner version that takes the least possible loops to get to the solution.
Do you have any ideas how to optimize this code?
Thanks
Code
Sub test()
Dim Result() As String
Dim Mydic As New Scripting.Dictionary
i = 0
Set Mydic = New Scripting.Dictionary
Mystring = "1, None, 0, None, None"
Result = Split(Mystring, ",")
mycount = UBound(Split(Mystring, "None"))
Do
DoEvents
myiter = myiter + 1
For ii = LBound(Result()) To UBound(Result())
If Trim(Result(ii)) = "None" Then
output = Int(2 * Rnd)
Else
output = Trim(Result(ii))
End If
mytext = mytext & output & ","
Next ii
mytext = Left(mytext, Len(mytext) - 1)
If Not Mydic.Exists(mytext) Then
Mydic.Add mytext, i
i = i + 1
End If
mytext = ""
Loop Until i = 2 ^ mycount
Debug.Print "Solution found in " & myiter & " loops :"
For Each ikey In Mydic.Keys
Debug.Print ikey
Next ikey
End Sub
Display More