-2

Okay so currently I have this code and I tried just putting ss where the quotes are down where it says "Where I want SS to be added" but it didn't work so I looked into the issue and with no help I have come to you guys. I messed up my last question so I hope that I do some what well on this one but anyways here is my current code that I used based on Eric Lippert's blog post

Public Class Form1
Private Function CartesianProduct(Of T)(ParamArray sequences As T()()) As T()()

    ' base case: 
    Dim result As IEnumerable(Of T()) = {New T() {}}
    For Each sequence In sequences
        Dim s = sequence
        ' don't close over the loop variable 
        ' recursive case: use SelectMany to build the new product out of the old one 
        result = From seq In result
                 From item In s
                 Select seq.Concat({item}).ToArray()
    Next
    Return result.ToArray()
End Function
Dim s1 As String() = New String() {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
Dim s2 As String() = New String() {"1", "2", "3", "4", "5", "6", "7", "8", "9"}

Dim ss As String()() = CartesianProduct(s1, s1, s2, s2, s2, s2, s1, s1)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    TextBox1.Text = TextBox1.Text + "000" + "Where I want SS to be added to"
End Sub

End Class

Eric Lippert
  • 647,829
  • 179
  • 1,238
  • 2,067
  • How do you expect it to be formatted in the output? – Steven Doggart Feb 06 '15 at 22:20
  • Just as text like if you look at how ss is made I want it to come out with the order that is used in above so an example would be xx1234xx and I want it added to the list box with 000 prior so I can use Notepad++ to make it into list form – ImTheTopOfKEK Feb 06 '15 at 22:25
  • I noticed that those are are one-character strings. You could actually get _greatly_ improved efficiency if you defined those as characters, rather than strings. – Joel Coehoorn Feb 07 '15 at 05:54
  • For your information, the string concatenation operator used in Visual Basic is recommended to be `&`, not `+`. http://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in-vb-net – Visual Vincent Feb 07 '15 at 10:19

2 Answers2

0

You can use LINQ's the Select method to transform the two-dimensional ss array into a single-dimension string array. For instance, if you just want to concatenate all of the strings in the second-dimension with no delimiters between them, you can use String.Join in the Select, like this:

Dim result As String() = ss.Select(Of String)(Function(x) "000" & String.Join("", x)).ToArray()

Then you can take that 1-D string array and add it to a ListBox using its AddRange method, like this:

ListBox1.Items.AddRange(ss.Select(Of String)(Function(x) String.Join("", x)).ToArray())
Steven Doggart
  • 43,358
  • 8
  • 68
  • 105
  • So if I do that then will it allow me to make the listbox/textbox have 8 character strings using the algorithm "xx1234xx" 1234 = 1-9 xx = a-z – ImTheTopOfKEK Feb 06 '15 at 22:48
  • Sorry. You've lost me. I'm not understanding what you mean. – Steven Doggart Feb 06 '15 at 22:50
  • Okay my program atlteast what im trying to do is generate outcomes using s1 and s2 to make 8 character combonations I'd like to be able to save them into the text document via copy paste from my program hence the textbox. – ImTheTopOfKEK Feb 06 '15 at 22:52
0
Public Class Form1
Dim MyMin As Integer = 1
Dim MyMax As Integer = 9
Dim My1stRandomNumber As Integer
Dim My2ndRandomNumber As Integer


Dim Generator As System.Random = New System.Random()
Dim prng As New Random
Const minCH As Integer = 2
Const maxCH As Integer = 2

Const randCH As String = "abcdefghijklmnopqrstuvwxyz"

Private Function RandomString() As String
    Dim sb As New System.Text.StringBuilder
    For i As Integer = 1 To prng.Next(minCH, maxCH + 1)
        sb.Append(randCH.Substring(prng.Next(0, randCH.Length), 1))
    Next
    Return sb.ToString()
End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Timer1.Enabled = True

End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Label1.Text = Generator.Next(MyMin, MyMax + 1)
    Label2.Text = Generator.Next(MyMin, MyMax + 1)
    Label3.Text = Generator.Next(MyMin, MyMax + 1)
    Label4.Text = Generator.Next(MyMin, MyMax + 1)
    Label5.Text = RandomString()
    Label6.Text = RandomString()
    TextBox1.Text = TextBox1.Text + "$" + Label6.Text + Label1.Text + Label2.Text + Label3.Text + Label4.Text + Label5.Text
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Enabled = False
End Sub

End Class

Is how I fixed it just switched the integer type firing using multiple Labels and a timer to loop.