Click here to Skip to main content
15,867,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code that loops from A to D and displays the result in a text box as the loop continues.

VB
Dim test(0 To 3) As String

test(0) = "A"
test(1) = "B"
test(2) = "C"
test(3) = "D"

For i As Int32 = 0 To test.Length - 1
TextBox4.Text = test(i)
TextBox4.Refresh()
Me.Refresh()
Next


But the problem is that the loop only goes like A , B , C ,D
How can I make the loop try all permutations so it's :
A
B
C
D
AA
AB
AC ....and so on?
Posted

This CodeProject article - Permutations, Combinations, and Variations using C# Generics[^] should give you all you need as to the "how" of doing it.

It's presented in C# but there are free on-line sites[^] that will convert to vb.net if you can't do it yourself
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Jun-14 14:21pm    
5ed.
—SA
Given you the answer is too trivial but it is not going to help you to learn.
Programming aside, what would you do if you have to solve it manually without computer:
Let n starts from 0, i.e. n = 0, loop
1.   Pick out the nth letter in the test array
     1.1.  m = n + 1, loop
     1.2.  pick out the mth letter in the test array, concatenate with the nth letter
     1.3.  If there is any letter after mth, then 
               1.3.1.  m = m + 1
               1.3.2.  Goto 1.2
           else
               1.3.3.  n = n +1
               1.3.4   goto 1

I see that you can make the first for loop worked, now translate the above into another for loop. After all, that is your homework.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900