Resolved Putting Data into multiple textboxes

jcardana

Old to VB6, New to VB.NET
Joined
Oct 26, 2015
Messages
72
Location
Rio Rancho, NM
Programming Experience
Beginner
Is there a way to avoid the code structure listed below?
I'm using For Each CTRL As Control In Me.Controls to GET the TEXT from each box, but what about PUTTING text into a specific box?

As always, Thank you for your time and efforts,
Joe


VB.NET:
        Select Case BankNumber
            Case 1
                Select Case PresetNumber
                    Case 0
                        txtPresetA0.Text = Trim(ReadPresetname)
                    Case 1
                        txtPresetA1.Text = Trim(ReadPresetname)
                    Case 2
                        txtPresetA2.Text = Trim(ReadPresetname)
                    Case 3
                        txtPresetA3.Text = Trim(ReadPresetname)
                    Case 4
                        txtPresetA4.Text = Trim(ReadPresetname)
                    Case 5
                        txtPresetA5.Text = Trim(ReadPresetname)
                    Case 6
                        txtPresetA6.Text = Trim(ReadPresetname)
                    Case 7
                        txtPresetA7.Text = Trim(ReadPresetname)
                    Case 8
                        txtPresetA8.Text = Trim(ReadPresetname)
                    Case 9
                        txtPresetA9.Text = Trim(ReadPresetname)
                    Case 10
                        txtPresetA10.Text = Trim(ReadPresetname)
                End Select
            Case 2
                Select Case PresetNumber
                    Case 0
                        txtPresetB0.Text = Trim(ReadPresetname)
                    Case 1
                        txtPresetB1.Text = Trim(ReadPresetname)
                    Case 2
                        txtPresetB2.Text = Trim(ReadPresetname)
                    Case 3
                        txtPresetB3.Text = Trim(ReadPresetname)
                    Case 4
                        txtPresetB4.Text = Trim(ReadPresetname)
                    Case 5
                        txtPresetB5.Text = Trim(ReadPresetname)
                    Case 6
                        txtPresetB6.Text = Trim(ReadPresetname)
                    Case 7
                        txtPresetB7.Text = Trim(ReadPresetname)
                    Case 8
                        txtPresetB8.Text = Trim(ReadPresetname)
                    Case 9
                        txtPresetB9.Text = Trim(ReadPresetname)
                    Case 10
                        txtPresetB10.Text = Trim(ReadPresetname)
                End Select
            Case 3
                Select Case PresetNumber
                    Case 0
                        txtPresetC0.Text = Trim(ReadPresetname)
                    Case 1
                        txtPresetC1.Text = Trim(ReadPresetname)
                    Case 2
                        txtPresetC2.Text = Trim(ReadPresetname)
                    Case 3
                        txtPresetC3.Text = Trim(ReadPresetname)
                    Case 4
                        txtPresetC4.Text = Trim(ReadPresetname)
                    Case 5
                        txtPresetC5.Text = Trim(ReadPresetname)
                    Case 6
                        txtPresetC6.Text = Trim(ReadPresetname)
                    Case 7
                        txtPresetC7.Text = Trim(ReadPresetname)
                    Case 8
                        txtPresetC8.Text = Trim(ReadPresetname)
                    Case 9
                        txtPresetC9.Text = Trim(ReadPresetname)
                    Case 10
                        txtPresetC10.Text = Trim(ReadPresetname)
                End Select
            Case 4
                Select Case PresetNumber
                    Case 0
                        txtPresetD0.Text = Trim(ReadPresetname)
                    Case 1
                        txtPresetD1.Text = Trim(ReadPresetname)
                    Case 2
                        txtPresetD2.Text = Trim(ReadPresetname)
                    Case 3
                        txtPresetD3.Text = Trim(ReadPresetname)
                    Case 4
                        txtPresetD4.Text = Trim(ReadPresetname)
                    Case 5
                        txtPresetD5.Text = Trim(ReadPresetname)
                    Case 6
                        txtPresetD6.Text = Trim(ReadPresetname)
                    Case 7
                        txtPresetD7.Text = Trim(ReadPresetname)
                    Case 8
                        txtPresetD8.Text = Trim(ReadPresetname)
                    Case 9
                        txtPresetD9.Text = Trim(ReadPresetname)
                    Case 10
                        txtPresetD10.Text = Trim(ReadPresetname)
                End Select
            Case 5
                Select Case PresetNumber
                    Case 0
                        txtPresetE0.Text = Trim(ReadPresetname)
                    Case 1
                        txtPresetE1.Text = Trim(ReadPresetname)
                    Case 2
                        txtPresetE2.Text = Trim(ReadPresetname)
                    Case 3
                        txtPresetE3.Text = Trim(ReadPresetname)
                    Case 4
                        txtPresetE4.Text = Trim(ReadPresetname)
                    Case 5
                        txtPresetE5.Text = Trim(ReadPresetname)
                    Case 6
                        txtPresetE6.Text = Trim(ReadPresetname)
                    Case 7
                        txtPresetE7.Text = Trim(ReadPresetname)
                    Case 8
                        txtPresetE8.Text = Trim(ReadPresetname)
                    Case 9
                        txtPresetE9.Text = Trim(ReadPresetname)
                    Case 10
                        txtPresetE10.Text = Trim(ReadPresetname)
                End Select
        End Select
 
Solution
You can use for example arrays:
VB.NET:
Dim A = {txtPresetA0, txtPresetA1, txtPresetA2}
Dim B = {txtPresetB0, txtPresetB1, txtPresetB2}
Dim all = {A, B}

all(BankNumber)(PresentNumber).Text = Trim(ReadPresetname)
If numbers were (0)(1) it would set txtPresetA1.
You can use for example arrays:
VB.NET:
Dim A = {txtPresetA0, txtPresetA1, txtPresetA2}
Dim B = {txtPresetB0, txtPresetB1, txtPresetB2}
Dim all = {A, B}

all(BankNumber)(PresentNumber).Text = Trim(ReadPresetname)
If numbers were (0)(1) it would set txtPresetA1.
 
Solution
I never would have thought to use arrays to build a control name.
THANK YOU!!!
 
Back
Top