title: Print all the possible combinations of "X" amount of characters with "X" string length (Brute Force)
body: <p>I'm trying to write a word combination generator, I mean to print all the possible combinations of "X" amount of characters with "X" string length,</p>
  
  <p>First of all I need to say I saw a question in StackOverFlow about exactly this problem which have a lot of answers of word generators to do exaclty this (on different languages), but please, don't mark this as duplicate or don't comment my question only to reference-me that link 'cause I've tested ALL the C# and VBNET codes of that question and really none works 100% as expected, see the combinations I need: </p>
  
  <p>For example, If I have "a","b" and "c" characters, and I want to make all combinations of those characters in a string of "3" length then this is the result I expect:</p>
  
  <pre><code>' Expected result, 27 combinations:
  '
  ' aaa
  ' aab
  ' aac
  '
  ' aba
  ' abb
  ' abc
  '
  ' aca
  ' acb
  ' acc
  '
  ' baa
  ' bab
  ' bac
  '
  ' bba
  ' bbb
  ' bbc
  '
  ' bca
  ' bcb
  ' bcc
  '
  ' caa
  ' cab
  ' cac
  '
  ' cba
  ' cbb
  ' cbc
  '
  ' cca
  ' ccb
  ' ccc
  </code></pre>
  
  <p>(The sort don't matter, I can sort it later.)</p>
  
  <p>...But so far of that expected result this is what I could get:</p>
  
  <pre><code>'a
  'aa
  'aaa
  'b
  'bb
  'bbb
  'c
  'cc
  'ccc
  </code></pre>
  
  <p>I have done this time ago in two languages (Ruby and Batch) but using nested Fors (A lot of Fors together each For appending only one letter to the other For output), of course If I'm trying to do this in VBNET is to avoid the suing of a lot of Fors, and to do it in a better performance way.</p>
  
  <p>In the code below you can see how I try to allocate all the combinations at RAM memory (an array) instead of writing they to the physical disk, so I want to write this code using a logic method and in a better performance way, then I want to save all the combinations "in the memory" first and thats the reason too why I don't want to use a lot of fors (the performance).</p>
  
  <p>This was my last try, all is explained in comment-lines:</p>
  
  <pre><code>Public Class Form1
  
      Dim characters As Char()  ' Default value: {"a","b","c"}
      Dim StringLength As Int64 ' Default value: 3
      Dim TotalCombinations As Int64 ' Default value: 27
      Dim strarray(99999999) As String ' Default size: "99.999.999" million of combinations in memory (I need to confirm this from an expert).
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      Dim index As Int64 = 0
  
      For column As Int64 = 0 To TotalCombinations - 1 ' For 0 to 26
  
          For Each character As Char In characters ' Characters = {"a","b","c"}
  
              If column &lt; index Then
                  index = 0 ' I reset index value 'cause... just experimenting things.
                  Try
                      strarray(index) += characters(index)
                      RichTextBox1.Text += strarray(index) &amp; ControlChars.NewLine
                  Catch
                  End Try
              Else
                  Try
                      strarray(index) += characters(index)
                      RichTextBox1.Text += strarray(index) &amp; ControlChars.NewLine
                  Catch
                  End Try
              End If
          Next
  
          index += 1
  
      Next
  
      End Sub
  
      Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
          characters = sender.text.ToCharArray ' Result: {"a","b","c"}
          Calculate_Combinations() ' Result: 27
      End Sub
  
      Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
          StringLength = sender.value ' Result: 3
          Calculate_Combinations() ' Result: 27
      End Sub
  
      Private Sub Calculate_Combinations()
          Try
              TotalCombinations = ((characters.LongLength * StringLength) * StringLength) ' Result: 27
              Label1.Text = ((characters.LongLength * StringLength) * StringLength) &amp; " number of combinations." ' Result: 27
          Catch : End Try
      End Sub
  
  End Class
  </code></pre>
  
  <p>I precise help.</p>