Goodday great Programmers in the World

Am not advanced upto this extent and have to ask for help

I need a help and codes to solve this.
I have 5 columns of 11 textboxes each on my form
the textboxes are generated with this code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        

        'column 1 textboxes
        'Dim tbarray(10) As TextBox
        For u As Integer = 0 To 10
            Dim tbox As TextBox = New TextBox

            With tbox
                .Parent = Me
                .Left = (u Mod 5) * 45 + 100
                .Top = (u \ 5) * 25 + 6
                .Width = 30
                .Visible = True
                .Tag = u
                .Text = ""
                .MaxLength = 2
                .Name = "textboxfrom_" & u
                Me.Controls.Add(tbox)

                .Location = New Point(1148, 40 + (u * 30))
            End With
        Next
        'end of column 1 textboxes


        'column 2 textboxes
        'Dim tbarray(10) As TextBox
        For u As Integer = 0 To 10
            Dim tbox As TextBox = New TextBox

            With tbox
                .Parent = Me
                .Left = (u Mod 10) * 45 + 100
                .Top = (u \ 10) * 25 + 6
                .Width = 30
                .Visible = True
                .Tag = u
                .Text = ""
                .MaxLength = 2
                .Name = "textboxfrom_" & u
                Me.Controls.Add(tbox)
                .Location = New Point(1192, 40 + (u * 30))
            End With
        Next
        'end of column 2 textboxes



        'column 3 textboxes
        'Dim tbarray(10) As TextBox
        For u As Integer = 0 To 10
            Dim tbox As TextBox = New TextBox

            With tbox
                .Parent = Me
                .Left = (u Mod 10) * 45 + 100
                .Top = (u \ 10) * 25 + 6
                .Width = 30
                .Visible = True
                .Tag = u
                .Text = ""
                .MaxLength = 2
                .Name = "textboxfrom_" & u
                Me.Controls.Add(tbox)
                .Location = New Point(1236, 40 + (u * 30))
            End With
        Next
        'end of column 3 textboxes



        'column 4 textboxes
        'Dim tbarray(10) As TextBox
        For u As Integer = 0 To 10
            Dim tbox As TextBox = New TextBox

            With tbox
                .Parent = Me
                .Left = (u Mod 10) * 45 + 100
                .Top = (u \ 10) * 25 + 6
                .Width = 30
                .Visible = True
                .Tag = u
                .Text = ""
                .MaxLength = 2
                .Name = "textboxfrom_" & u
                Me.Controls.Add(tbox)
                .Location = New Point(1280, 40 + (u * 30))
            End With
        Next
        'end of column 4 textboxes


        'column 5 textboxes
        'Dim tbarray(10) As TextBox
        For u As Integer = 0 To 10
            Dim tbox As TextBox = New TextBox

            With tbox
                .Parent = Me
                .Left = (u Mod 10) * 45 + 100
                .Top = (u \ 10) * 25 + 6
                .Width = 30
                .Visible = True
                .Tag = u
                .Text = ""
                .MaxLength = 2
                .Name = "textboxfrom_" & u
                Me.Controls.Add(tbox)
                .Location = New Point(1324, 40 + (u * 30))
            End With
        Next
        'end of column 5 textboxes

    End Sub

Please i need a code to generate all the possible combination of the numbers a user types into the textboxes

i have two images (Panel3: the textboxes where added during design time)
image2: the textboex were added using the code i gave about

Please if you know the best approach to generate all the possible combinations of numbers typed into the textboxes (Example see panel3.jpg image) help me out,

let me explain More on this

The user will type in the desired unique numbers into the textboxes without repetition (Please see the image i did not repeat any number, so can the code detect when a number have been typed twice?) Else when running the program i will be carefull not typing two numbers twice, but its adviceable to detect when a number is typed more than once.

Then the amount of unique number the user will type or supply to the desired textboxes does not matter here and as you can see in the image the amount of numbers in each column is not the same ie it may or may not be same amount (but number must be unique. Please try and see if it can be done to prompt user to enter the amount of numbers to supply in each column)

Then After supplying the numbers just like the one in Image, The button Click will generate all the Possible Combinations of the all the numbers typed into the textboxes in the columns.. Then After generating the combinations in the Listbox, the next Button will be able to delete them from the Universal 90c5 just like the former.

1000 thanks in advance. Great Programmer Please Arrest my case

You do realize that 55 numbers taken 5 at a time is 3,478,761 combinations? Or did you mean that it needs to select one number from column 1, one number from column 2, etc? If so, then you have 161,051 combinations. That's a lot for one listbox.

Could you explain more exactly what you want?

To not have a similar # added to another TextBox, I used the .Validated event, which when the selected TextBox looses focus, it fires.
To have this work, you need to add this line of code to each of your loops that creates a TextBox, possibly right before adding the TextBox to the Form.

AddHandler .Validated, AddressOf _TextBoxes_Validated

And the code that makes it all work, is this:

Private txtSelected As TextBox = Nothing '// declared once.

    Private Sub _TextBoxes_Validated(sender As Object, e As System.EventArgs)
        txtSelected = CType(sender, TextBox) '// get selected TextBox.
        For Each ctl As Control In Me.Controls '// loop thru all Controls.
            If TypeOf ctl Is TextBox AndAlso ctl.Name.StartsWith("textboxfrom_") Then '// find TextBoxes that have .Names starting with "textboxfrom_".
                If Not txtSelected Is ctl AndAlso txtSelected.Text = ctl.Text Then'// if Not TextBox typed in is the TextBox in the loop and if .Text=.Text of loop Textbox.
                    txtSelected.Focus() : txtSelected.SelectAll() '// set focus and select all text if same # in another TextBox.
                    MsgBox("Similar # in another TextBox", MsgBoxStyle.Critical) '// prompt if needed.
                End If
            End If
        Next
    End Sub

Regarding:
>>...generate all the possible combination of the numbers a user types into the textboxes
Are you trying to add numbers as 1,2,3,4,5,etc. in the TextBoxes, and have the numbers added to the ListBox in Random order?
For example, you have 1,2,3,4,5 in 5 TextBoxes, and the ListBox should add items of "1,3,2,4,5","1,4,3,2,5","5,4,3,2,1", and so on?
If I'm on the right path, do let me know, if not, do explain a little better.

Hope this helps.

You do realize that 55 numbers taken 5 at a time is 3,478,761 combinations? Or did you mean that it needs to select one number from column 1, one number from column 2, etc? If so, then you have 161,051 combinations. That's a lot for one listbox.

Hi Momerath
i have generated all the possible combinations of 90c5 which is above 43million combinations eg: 3,6,8,48,89 is a possible combination of 90c5, and i a have generated all of them, but it took a long time.

Now i want the user to type in numbers in the text boxes arranged in a 5 column form
with range 1-90 without repeating a number. the problem is how to capture the numbers in the textboxes and perform generate all possible combination of them. deleting the combinations from the universal set is not a problem to me.

To not have a similar # added to another TextBox, I used the .Validated event, which when the selected TextBox looses focus, it fires.
To have this work, you need to add this line of code to each of your loops that creates a TextBox, possibly right before adding the TextBox to the Form.
VB.NET Syntax (Toggle Plain Text)

1.
AddHandler .Validated, AddressOf _TextBoxes_Validated

AddHandler .Validated, AddressOf _TextBoxes_Validated
And the code that makes it all work, is this:
VB.NET Syntax (Toggle Plain Text)

1.
Private txtSelected As TextBox = Nothing '// declared once.
2.

3.
Private Sub _TextBoxes_Validated(sender As Object, e As System.EventArgs)
4.
txtSelected = CType(sender, TextBox) '// get selected TextBox.
5.
For Each ctl As Control In Me.Controls '// loop thru all Controls.
6.
If TypeOf ctl Is TextBox AndAlso ctl.Name.StartsWith("textboxfrom_") Then '// find TextBoxes that have .Names starting with "textboxfrom_".
7.
If Not txtSelected Is ctl AndAlso txtSelected.Text = ctl.Text Then'// if Not TextBox typed in is the TextBox in the loop and if .Text=.Text of loop Textbox.
8.
txtSelected.Focus() : txtSelected.SelectAll() '// set focus and select all text if same # in another TextBox.
9.
MsgBox("Similar # in another TextBox", MsgBoxStyle.Critical) '// prompt if needed.
10.
End If
11.
End If
12.
Next
13.
End Sub

Private txtSelected As TextBox = Nothing '// declared once. Private Sub _TextBoxes_Validated(sender As Object, e As System.EventArgs) txtSelected = CType(sender, TextBox) '// get selected TextBox. For Each ctl As Control In Me.Controls '// loop thru all Controls. If TypeOf ctl Is TextBox AndAlso ctl.Name.StartsWith("textboxfrom_") Then '// find TextBoxes that have .Names starting with "textboxfrom_". If Not txtSelected Is ctl AndAlso txtSelected.Text = ctl.Text Then'// if Not TextBox typed in is the TextBox in the loop and if .Text=.Text of loop Textbox. txtSelected.Focus() : txtSelected.SelectAll() '// set focus and select all text if same # in another TextBox. MsgBox("Similar # in another TextBox", MsgBoxStyle.Critical) '// prompt if needed. End If End If Next End Sub
Regarding:
>>...generate all the possible combination of the numbers a user types into the textboxes

Hi codeorder

Your suggestion is good and need but it has be coded to suit the program.
please code it to use variables in the codes am currently using or you can recode my own code ( the textboxes generating codes) to suit your own code, and that will be good and nice. thanks alot for your unalloyed idea.


The textboxes have a maxLength = 2
The numbers to be typed into the text boxes are numbers within 1-90 and each must be unique and the we will Generating all the possible combinations of the numbers typed in the text box
example

C1 C2 C3 C4 C5

23 56 33 11 9

19 8 49 59 20

22 - 10 5 66

- - 4 40 14

- - - 38 -

Let me throw more light on this

so it should be able to perform all the possible combinations. And the combination will not be based on each column. The combination will be generated from all the numbers in the 5 columns, else the aim has failed. Its about generating All the possible combinations from numbers typed into the 5 columns.


The user will have to fill in the textboxes from the top down, its not a must he must fill in all textboxes in each column (this will bring up asking the user 4 amount of textboxes he intends to fill for each column before he starts filling the textboxes). You may have a better way or method to do it, then use urs if it better.

Now i want the user to type in numbers in the text boxes arranged in a 5 column form with range 1-90 without repeating a number. the problem is how to capture the numbers in the textboxes and perform generate all possible combination of them. deleting the combinations from the universal set is not a problem to me.

Create a List<T> of textboxes in your form. As you generate each textbox, add it to the list. When you want to get the numbers, iterate through the list and if the current textbox has a value, convert it from a string to an integer and add it to a new List<T> of integers. When you are done, generate all the combinations of the integer list that you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.