vb.net How save and Load all textbox data on form to to a file

I am trying to save the values from textboxes and other controls recursively when my form has:
(1) tabcontrols with multiple tabPages
(2) on each tabPage are:
                   (a) several groupboxes, within a GroupBox
                   (b) panels, textboxes, and combboxes on the several groupboxes

I would like to use a similar method below but I don't get all the textboxes

For Each controlType As Control In Me.Controls
                    If TypeOf controlType Is TabControl Then
                        For Each tabpage As Control In controlType.Controls
                            If TypeOf controlType Is GroupBox Then
                                For Each txtBox As Control In controlType.Controls
                                    If TypeOf txtBox Is TextBox Then
                                        outputFile.wplWriteLine(txtBox.Name, Trim(txtBox.Text))
                                    End If
                                Next
                            End If
                        Next
                    End If
                Next
taviafAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
it_saigeDeveloperCommented:
Rather than trying to TypeOf all over the place, might be better just to resolve the ControlControl collection for each control recursively.  Something like:

Form1.vb -
Imports System.IO
Imports System.Windows.Forms.Control

Public Class Form1
	Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
		Controls.FillTextBoxes()
		Using file As New FileStream("MyTextBoxes.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
			Using writer As New StreamWriter(file)
				Controls.WriteFormToFile(writer)
			End Using
		End Using
	End Sub
End Class

Module Extensions
	<System.Runtime.CompilerServices.Extension()> _
	Public Sub FillTextBoxes(ByVal controls As ControlCollection)
		For Each [control] As Control In controls
			If [control].Controls.Count <> 0 Then
				[control].Controls.FillTextBoxes()
			Else
				If TypeOf [control] Is TextBox Then
					Dim tb As TextBox = DirectCast([control], TextBox)
					tb.Text = If(tb.Parent IsNot Nothing, String.Format("{0}{1}", tb.Parent.Name, tb.Name), tb.Name)
				End If
			End If
		Next
	End Sub

	<System.Runtime.CompilerServices.Extension()> _
	Public Sub WriteFormToFile(ByVal controls As ControlCollection, ByVal writer As StreamWriter)
		For Each [control] As Control In controls
			If [control].Controls.Count <> 0 Then
				[control].Controls.WriteFormToFile(writer)
			Else
				If TypeOf [control] Is TextBox Then
					Dim tb As TextBox = DirectCast([control], TextBox)
					writer.WriteLine("{0} = {1}", tb.Name, tb.Text.Trim())
				End If
			End If
		Next
	End Sub
End Module

Open in new window

Form1.Designer.vb -
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
		Me.TabControl1 = New System.Windows.Forms.TabControl()
		Me.TabPage1 = New System.Windows.Forms.TabPage()
		Me.TabPage2 = New System.Windows.Forms.TabPage()
		Me.TabPage3 = New System.Windows.Forms.TabPage()
		Me.TabPage4 = New System.Windows.Forms.TabPage()
		Me.Panel1 = New System.Windows.Forms.Panel()
		Me.TextBox1 = New System.Windows.Forms.TextBox()
		Me.TextBox2 = New System.Windows.Forms.TextBox()
		Me.TextBox3 = New System.Windows.Forms.TextBox()
		Me.Panel2 = New System.Windows.Forms.Panel()
		Me.TextBox4 = New System.Windows.Forms.TextBox()
		Me.TextBox5 = New System.Windows.Forms.TextBox()
		Me.TextBox6 = New System.Windows.Forms.TextBox()
		Me.Panel3 = New System.Windows.Forms.Panel()
		Me.TextBox7 = New System.Windows.Forms.TextBox()
		Me.TextBox8 = New System.Windows.Forms.TextBox()
		Me.TextBox9 = New System.Windows.Forms.TextBox()
		Me.Panel4 = New System.Windows.Forms.Panel()
		Me.TextBox10 = New System.Windows.Forms.TextBox()
		Me.TextBox11 = New System.Windows.Forms.TextBox()
		Me.TextBox12 = New System.Windows.Forms.TextBox()
		Me.Panel5 = New System.Windows.Forms.Panel()
		Me.TextBox13 = New System.Windows.Forms.TextBox()
		Me.TextBox14 = New System.Windows.Forms.TextBox()
		Me.TextBox15 = New System.Windows.Forms.TextBox()
		Me.Panel6 = New System.Windows.Forms.Panel()
		Me.TextBox16 = New System.Windows.Forms.TextBox()
		Me.TextBox17 = New System.Windows.Forms.TextBox()
		Me.TextBox18 = New System.Windows.Forms.TextBox()
		Me.Panel7 = New System.Windows.Forms.Panel()
		Me.TextBox19 = New System.Windows.Forms.TextBox()
		Me.TextBox20 = New System.Windows.Forms.TextBox()
		Me.TextBox21 = New System.Windows.Forms.TextBox()
		Me.Panel8 = New System.Windows.Forms.Panel()
		Me.TextBox22 = New System.Windows.Forms.TextBox()
		Me.TextBox23 = New System.Windows.Forms.TextBox()
		Me.TextBox24 = New System.Windows.Forms.TextBox()
		Me.Panel9 = New System.Windows.Forms.Panel()
		Me.TextBox25 = New System.Windows.Forms.TextBox()
		Me.TextBox26 = New System.Windows.Forms.TextBox()
		Me.TextBox27 = New System.Windows.Forms.TextBox()
		Me.Panel10 = New System.Windows.Forms.Panel()
		Me.TextBox28 = New System.Windows.Forms.TextBox()
		Me.TextBox29 = New System.Windows.Forms.TextBox()
		Me.TextBox30 = New System.Windows.Forms.TextBox()
		Me.Panel11 = New System.Windows.Forms.Panel()
		Me.TextBox31 = New System.Windows.Forms.TextBox()
		Me.TextBox32 = New System.Windows.Forms.TextBox()
		Me.TextBox33 = New System.Windows.Forms.TextBox()
		Me.Panel12 = New System.Windows.Forms.Panel()
		Me.TextBox34 = New System.Windows.Forms.TextBox()
		Me.TextBox35 = New System.Windows.Forms.TextBox()
		Me.TextBox36 = New System.Windows.Forms.TextBox()
		Me.Panel13 = New System.Windows.Forms.Panel()
		Me.TextBox37 = New System.Windows.Forms.TextBox()
		Me.TextBox38 = New System.Windows.Forms.TextBox()
		Me.TextBox39 = New System.Windows.Forms.TextBox()
		Me.Panel14 = New System.Windows.Forms.Panel()
		Me.TextBox40 = New System.Windows.Forms.TextBox()
		Me.TextBox41 = New System.Windows.Forms.TextBox()
		Me.TextBox42 = New System.Windows.Forms.TextBox()
		Me.Panel15 = New System.Windows.Forms.Panel()
		Me.TextBox43 = New System.Windows.Forms.TextBox()
		Me.TextBox44 = New System.Windows.Forms.TextBox()
		Me.TextBox45 = New System.Windows.Forms.TextBox()
		Me.Panel16 = New System.Windows.Forms.Panel()
		Me.TextBox46 = New System.Windows.Forms.TextBox()
		Me.TextBox47 = New System.Windows.Forms.TextBox()
		Me.TextBox48 = New System.Windows.Forms.TextBox()
		Me.TabControl1.SuspendLayout()
		Me.TabPage1.SuspendLayout()
		Me.TabPage2.SuspendLayout()
		Me.TabPage3.SuspendLayout()
		Me.TabPage4.SuspendLayout()
		Me.Panel1.SuspendLayout()
		Me.Panel2.SuspendLayout()
		Me.Panel3.SuspendLayout()
		Me.Panel4.SuspendLayout()
		Me.Panel5.SuspendLayout()
		Me.Panel6.SuspendLayout()
		Me.Panel7.SuspendLayout()
		Me.Panel8.SuspendLayout()
		Me.Panel9.SuspendLayout()
		Me.Panel10.SuspendLayout()
		Me.Panel11.SuspendLayout()
		Me.Panel12.SuspendLayout()
		Me.Panel13.SuspendLayout()
		Me.Panel14.SuspendLayout()
		Me.Panel15.SuspendLayout()
		Me.Panel16.SuspendLayout()
		Me.SuspendLayout()
		'
		'TabControl1
		'
		Me.TabControl1.Controls.Add(Me.TabPage1)
		Me.TabControl1.Controls.Add(Me.TabPage2)
		Me.TabControl1.Controls.Add(Me.TabPage3)
		Me.TabControl1.Controls.Add(Me.TabPage4)
		Me.TabControl1.Dock = System.Windows.Forms.DockStyle.Fill
		Me.TabControl1.Location = New System.Drawing.Point(0, 0)
		Me.TabControl1.Name = "TabControl1"
		Me.TabControl1.SelectedIndex = 0
		Me.TabControl1.Size = New System.Drawing.Size(479, 261)
		Me.TabControl1.TabIndex = 0
		'
		'TabPage1
		'
		Me.TabPage1.Controls.Add(Me.Panel13)
		Me.TabPage1.Controls.Add(Me.Panel14)
		Me.TabPage1.Controls.Add(Me.Panel15)
		Me.TabPage1.Controls.Add(Me.Panel16)
		Me.TabPage1.Location = New System.Drawing.Point(4, 22)
		Me.TabPage1.Name = "TabPage1"
		Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)
		Me.TabPage1.Size = New System.Drawing.Size(471, 235)
		Me.TabPage1.TabIndex = 0
		Me.TabPage1.Text = "TabPage1"
		Me.TabPage1.UseVisualStyleBackColor = True
		'
		'TabPage2
		'
		Me.TabPage2.Controls.Add(Me.Panel9)
		Me.TabPage2.Controls.Add(Me.Panel10)
		Me.TabPage2.Controls.Add(Me.Panel11)
		Me.TabPage2.Controls.Add(Me.Panel12)
		Me.TabPage2.Location = New System.Drawing.Point(4, 22)
		Me.TabPage2.Name = "TabPage2"
		Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)
		Me.TabPage2.Size = New System.Drawing.Size(471, 235)
		Me.TabPage2.TabIndex = 1
		Me.TabPage2.Text = "TabPage2"
		Me.TabPage2.UseVisualStyleBackColor = True
		'
		'TabPage3
		'
		Me.TabPage3.Controls.Add(Me.Panel5)
		Me.TabPage3.Controls.Add(Me.Panel6)
		Me.TabPage3.Controls.Add(Me.Panel7)
		Me.TabPage3.Controls.Add(Me.Panel8)
		Me.TabPage3.Location = New System.Drawing.Point(4, 22)
		Me.TabPage3.Name = "TabPage3"
		Me.TabPage3.Padding = New System.Windows.Forms.Padding(3)
		Me.TabPage3.Size = New System.Drawing.Size(471, 235)
		Me.TabPage3.TabIndex = 2
		Me.TabPage3.Text = "TabPage3"
		Me.TabPage3.UseVisualStyleBackColor = True
		'
		'TabPage4
		'
		Me.TabPage4.Controls.Add(Me.Panel4)
		Me.TabPage4.Controls.Add(Me.Panel3)
		Me.TabPage4.Controls.Add(Me.Panel2)
		Me.TabPage4.Controls.Add(Me.Panel1)
		Me.TabPage4.Location = New System.Drawing.Point(4, 22)
		Me.TabPage4.Name = "TabPage4"
		Me.TabPage4.Padding = New System.Windows.Forms.Padding(3)
		Me.TabPage4.Size = New System.Drawing.Size(471, 235)
		Me.TabPage4.TabIndex = 3
		Me.TabPage4.Text = "TabPage4"
		Me.TabPage4.UseVisualStyleBackColor = True
		'
		'Panel1
		'
		Me.Panel1.Controls.Add(Me.TextBox3)
		Me.Panel1.Controls.Add(Me.TextBox2)
		Me.Panel1.Controls.Add(Me.TextBox1)
		Me.Panel1.Location = New System.Drawing.Point(9, 7)
		Me.Panel1.Name = "Panel1"
		Me.Panel1.Size = New System.Drawing.Size(200, 100)
		Me.Panel1.TabIndex = 0
		'
		'TextBox1
		'
		Me.TextBox1.Location = New System.Drawing.Point(4, 4)
		Me.TextBox1.Name = "TextBox1"
		Me.TextBox1.Size = New System.Drawing.Size(100, 20)
		Me.TextBox1.TabIndex = 0
		'
		'TextBox2
		'
		Me.TextBox2.Location = New System.Drawing.Point(4, 30)
		Me.TextBox2.Name = "TextBox2"
		Me.TextBox2.Size = New System.Drawing.Size(100, 20)
		Me.TextBox2.TabIndex = 1
		'
		'TextBox3
		'
		Me.TextBox3.Location = New System.Drawing.Point(4, 56)
		Me.TextBox3.Name = "TextBox3"
		Me.TextBox3.Size = New System.Drawing.Size(100, 20)
		Me.TextBox3.TabIndex = 2
		'
		'Panel2
		'
		Me.Panel2.Controls.Add(Me.TextBox4)
		Me.Panel2.Controls.Add(Me.TextBox5)
		Me.Panel2.Controls.Add(Me.TextBox6)
		Me.Panel2.Location = New System.Drawing.Point(215, 7)
		Me.Panel2.Name = "Panel2"
		Me.Panel2.Size = New System.Drawing.Size(200, 100)
		Me.Panel2.TabIndex = 3
		'
		'TextBox4
		'
		Me.TextBox4.Location = New System.Drawing.Point(4, 56)
		Me.TextBox4.Name = "TextBox4"
		Me.TextBox4.Size = New System.Drawing.Size(100, 20)
		Me.TextBox4.TabIndex = 2
		'
		'TextBox5
		'
		Me.TextBox5.Location = New System.Drawing.Point(4, 30)
		Me.TextBox5.Name = "TextBox5"
		Me.TextBox5.Size = New System.Drawing.Size(100, 20)
		Me.TextBox5.TabIndex = 1
		'
		'TextBox6
		'
		Me.TextBox6.Location = New System.Drawing.Point(4, 4)
		Me.TextBox6.Name = "TextBox6"
		Me.TextBox6.Size = New System.Drawing.Size(100, 20)
		Me.TextBox6.TabIndex = 0
		'
		'Panel3
		'
		Me.Panel3.Controls.Add(Me.TextBox7)
		Me.Panel3.Controls.Add(Me.TextBox8)
		Me.Panel3.Controls.Add(Me.TextBox9)
		Me.Panel3.Location = New System.Drawing.Point(9, 113)
		Me.Panel3.Name = "Panel3"
		Me.Panel3.Size = New System.Drawing.Size(200, 100)
		Me.Panel3.TabIndex = 3
		'
		'TextBox7
		'
		Me.TextBox7.Location = New System.Drawing.Point(4, 56)
		Me.TextBox7.Name = "TextBox7"
		Me.TextBox7.Size = New System.Drawing.Size(100, 20)
		Me.TextBox7.TabIndex = 2
		'
		'TextBox8
		'
		Me.TextBox8.Location = New System.Drawing.Point(4, 30)
		Me.TextBox8.Name = "TextBox8"
		Me.TextBox8.Size = New System.Drawing.Size(100, 20)
		Me.TextBox8.TabIndex = 1
		'
		'TextBox9
		'
		Me.TextBox9.Location = New System.Drawing.Point(4, 4)
		Me.TextBox9.Name = "TextBox9"
		Me.TextBox9.Size = New System.Drawing.Size(100, 20)
		Me.TextBox9.TabIndex = 0
		'
		'Panel4
		'
		Me.Panel4.Controls.Add(Me.TextBox10)
		Me.Panel4.Controls.Add(Me.TextBox11)
		Me.Panel4.Controls.Add(Me.TextBox12)
		Me.Panel4.Location = New System.Drawing.Point(215, 113)
		Me.Panel4.Name = "Panel4"
		Me.Panel4.Size = New System.Drawing.Size(200, 100)
		Me.Panel4.TabIndex = 3
		'
		'TextBox10
		'
		Me.TextBox10.Location = New System.Drawing.Point(4, 56)
		Me.TextBox10.Name = "TextBox10"
		Me.TextBox10.Size = New System.Drawing.Size(100, 20)
		Me.TextBox10.TabIndex = 2
		'
		'TextBox11
		'
		Me.TextBox11.Location = New System.Drawing.Point(4, 30)
		Me.TextBox11.Name = "TextBox11"
		Me.TextBox11.Size = New System.Drawing.Size(100, 20)
		Me.TextBox11.TabIndex = 1
		'
		'TextBox12
		'
		Me.TextBox12.Location = New System.Drawing.Point(4, 4)
		Me.TextBox12.Name = "TextBox12"
		Me.TextBox12.Size = New System.Drawing.Size(100, 20)
		Me.TextBox12.TabIndex = 0
		'
		'Panel5
		'
		Me.Panel5.Controls.Add(Me.TextBox13)
		Me.Panel5.Controls.Add(Me.TextBox14)
		Me.Panel5.Controls.Add(Me.TextBox15)
		Me.Panel5.Location = New System.Drawing.Point(238, 120)
		Me.Panel5.Name = "Panel5"
		Me.Panel5.Size = New System.Drawing.Size(200, 100)
		Me.Panel5.TabIndex = 5
		'
		'TextBox13
		'
		Me.TextBox13.Location = New System.Drawing.Point(4, 56)
		Me.TextBox13.Name = "TextBox13"
		Me.TextBox13.Size = New System.Drawing.Size(100, 20)
		Me.TextBox13.TabIndex = 2
		'
		'TextBox14
		'
		Me.TextBox14.Location = New System.Drawing.Point(4, 30)
		Me.TextBox14.Name = "TextBox14"
		Me.TextBox14.Size = New System.Drawing.Size(100, 20)
		Me.TextBox14.TabIndex = 1
		'
		'TextBox15
		'
		Me.TextBox15.Location = New System.Drawing.Point(4, 4)
		Me.TextBox15.Name = "TextBox15"
		Me.TextBox15.Size = New System.Drawing.Size(100, 20)
		Me.TextBox15.TabIndex = 0
		'
		'Panel6
		'
		Me.Panel6.Controls.Add(Me.TextBox16)
		Me.Panel6.Controls.Add(Me.TextBox17)
		Me.Panel6.Controls.Add(Me.TextBox18)
		Me.Panel6.Location = New System.Drawing.Point(32, 120)
		Me.Panel6.Name = "Panel6"
		Me.Panel6.Size = New System.Drawing.Size(200, 100)
		Me.Panel6.TabIndex = 7
		'
		'TextBox16
		'
		Me.TextBox16.Location = New System.Drawing.Point(4, 56)
		Me.TextBox16.Name = "TextBox16"
		Me.TextBox16.Size = New System.Drawing.Size(100, 20)
		Me.TextBox16.TabIndex = 2
		'
		'TextBox17
		'
		Me.TextBox17.Location = New System.Drawing.Point(4, 30)
		Me.TextBox17.Name = "TextBox17"
		Me.TextBox17.Size = New System.Drawing.Size(100, 20)
		Me.TextBox17.TabIndex = 1
		'
		'TextBox18
		'
		Me.TextBox18.Location = New System.Drawing.Point(4, 4)
		Me.TextBox18.Name = "TextBox18"
		Me.TextBox18.Size = New System.Drawing.Size(100, 20)
		Me.TextBox18.TabIndex = 0
		'
		'Panel7
		'
		Me.Panel7.Controls.Add(Me.TextBox19)
		Me.Panel7.Controls.Add(Me.TextBox20)
		Me.Panel7.Controls.Add(Me.TextBox21)
		Me.Panel7.Location = New System.Drawing.Point(238, 14)
		Me.Panel7.Name = "Panel7"
		Me.Panel7.Size = New System.Drawing.Size(200, 100)
		Me.Panel7.TabIndex = 6
		'
		'TextBox19
		'
		Me.TextBox19.Location = New System.Drawing.Point(4, 56)
		Me.TextBox19.Name = "TextBox19"
		Me.TextBox19.Size = New System.Drawing.Size(100, 20)
		Me.TextBox19.TabIndex = 2
		'
		'TextBox20
		'
		Me.TextBox20.Location = New System.Drawing.Point(4, 30)
		Me.TextBox20.Name = "TextBox20"
		Me.TextBox20.Size = New System.Drawing.Size(100, 20)
		Me.TextBox20.TabIndex = 1
		'
		'TextBox21
		'
		Me.TextBox21.Location = New System.Drawing.Point(4, 4)
		Me.TextBox21.Name = "TextBox21"
		Me.TextBox21.Size = New System.Drawing.Size(100, 20)
		Me.TextBox21.TabIndex = 0
		'
		'Panel8
		'
		Me.Panel8.Controls.Add(Me.TextBox22)
		Me.Panel8.Controls.Add(Me.TextBox23)
		Me.Panel8.Controls.Add(Me.TextBox24)
		Me.Panel8.Location = New System.Drawing.Point(32, 14)
		Me.Panel8.Name = "Panel8"
		Me.Panel8.Size = New System.Drawing.Size(200, 100)
		Me.Panel8.TabIndex = 4
		'
		'TextBox22
		'
		Me.TextBox22.Location = New System.Drawing.Point(4, 56)
		Me.TextBox22.Name = "TextBox22"
		Me.TextBox22.Size = New System.Drawing.Size(100, 20)
		Me.TextBox22.TabIndex = 2
		'
		'TextBox23
		'
		Me.TextBox23.Location = New System.Drawing.Point(4, 30)
		Me.TextBox23.Name = "TextBox23"
		Me.TextBox23.Size = New System.Drawing.Size(100, 20)
		Me.TextBox23.TabIndex = 1
		'
		'TextBox24
		'
		Me.TextBox24.Location = New System.Drawing.Point(4, 4)
		Me.TextBox24.Name = "TextBox24"
		Me.TextBox24.Size = New System.Drawing.Size(100, 20)
		Me.TextBox24.TabIndex = 0
		'
		'Panel9
		'
		Me.Panel9.Controls.Add(Me.TextBox25)
		Me.Panel9.Controls.Add(Me.TextBox26)
		Me.Panel9.Controls.Add(Me.TextBox27)
		Me.Panel9.Location = New System.Drawing.Point(238, 120)
		Me.Panel9.Name = "Panel9"
		Me.Panel9.Size = New System.Drawing.Size(200, 100)
		Me.Panel9.TabIndex = 5
		'
		'TextBox25
		'
		Me.TextBox25.Location = New System.Drawing.Point(4, 56)
		Me.TextBox25.Name = "TextBox25"
		Me.TextBox25.Size = New System.Drawing.Size(100, 20)
		Me.TextBox25.TabIndex = 2
		'
		'TextBox26
		'
		Me.TextBox26.Location = New System.Drawing.Point(4, 30)
		Me.TextBox26.Name = "TextBox26"
		Me.TextBox26.Size = New System.Drawing.Size(100, 20)
		Me.TextBox26.TabIndex = 1
		'
		'TextBox27
		'
		Me.TextBox27.Location = New System.Drawing.Point(4, 4)
		Me.TextBox27.Name = "TextBox27"
		Me.TextBox27.Size = New System.Drawing.Size(100, 20)
		Me.TextBox27.TabIndex = 0
		'
		'Panel10
		'
		Me.Panel10.Controls.Add(Me.TextBox28)
		Me.Panel10.Controls.Add(Me.TextBox29)
		Me.Panel10.Controls.Add(Me.TextBox30)
		Me.Panel10.Location = New System.Drawing.Point(32, 120)
		Me.Panel10.Name = "Panel10"
		Me.Panel10.Size = New System.Drawing.Size(200, 100)
		Me.Panel10.TabIndex = 7
		'
		'TextBox28
		'
		Me.TextBox28.Location = New System.Drawing.Point(4, 56)
		Me.TextBox28.Name = "TextBox28"
		Me.TextBox28.Size = New System.Drawing.Size(100, 20)
		Me.TextBox28.TabIndex = 2
		'
		'TextBox29
		'
		Me.TextBox29.Location = New System.Drawing.Point(4, 30)
		Me.TextBox29.Name = "TextBox29"
		Me.TextBox29.Size = New System.Drawing.Size(100, 20)
		Me.TextBox29.TabIndex = 1
		'
		'TextBox30
		'
		Me.TextBox30.Location = New System.Drawing.Point(4, 4)
		Me.TextBox30.Name = "TextBox30"
		Me.TextBox30.Size = New System.Drawing.Size(100, 20)
		Me.TextBox30.TabIndex = 0
		'
		'Panel11
		'
		Me.Panel11.Controls.Add(Me.TextBox31)
		Me.Panel11.Controls.Add(Me.TextBox32)
		Me.Panel11.Controls.Add(Me.TextBox33)
		Me.Panel11.Location = New System.Drawing.Point(238, 14)
		Me.Panel11.Name = "Panel11"
		Me.Panel11.Size = New System.Drawing.Size(200, 100)
		Me.Panel11.TabIndex = 6
		'
		'TextBox31
		'
		Me.TextBox31.Location = New System.Drawing.Point(4, 56)
		Me.TextBox31.Name = "TextBox31"
		Me.TextBox31.Size = New System.Drawing.Size(100, 20)
		Me.TextBox31.TabIndex = 2
		'
		'TextBox32
		'
		Me.TextBox32.Location = New System.Drawing.Point(4, 30)
		Me.TextBox32.Name = "TextBox32"
		Me.TextBox32.Size = New System.Drawing.Size(100, 20)
		Me.TextBox32.TabIndex = 1
		'
		'TextBox33
		'
		Me.TextBox33.Location = New System.Drawing.Point(4, 4)
		Me.TextBox33.Name = "TextBox33"
		Me.TextBox33.Size = New System.Drawing.Size(100, 20)
		Me.TextBox33.TabIndex = 0
		'
		'Panel12
		'
		Me.Panel12.Controls.Add(Me.TextBox34)
		Me.Panel12.Controls.Add(Me.TextBox35)
		Me.Panel12.Controls.Add(Me.TextBox36)
		Me.Panel12.Location = New System.Drawing.Point(32, 14)
		Me.Panel12.Name = "Panel12"
		Me.Panel12.Size = New System.Drawing.Size(200, 100)
		Me.Panel12.TabIndex = 4
		'
		'TextBox34
		'
		Me.TextBox34.Location = New System.Drawing.Point(4, 56)
		Me.TextBox34.Name = "TextBox34"
		Me.TextBox34.Size = New System.Drawing.Size(100, 20)
		Me.TextBox34.TabIndex = 2
		'
		'TextBox35
		'
		Me.TextBox35.Location = New System.Drawing.Point(4, 30)
		Me.TextBox35.Name = "TextBox35"
		Me.TextBox35.Size = New System.Drawing.Size(100, 20)
		Me.TextBox35.TabIndex = 1
		'
		'TextBox36
		'
		Me.TextBox36.Location = New System.Drawing.Point(4, 4)
		Me.TextBox36.Name = "TextBox36"
		Me.TextBox36.Size = New System.Drawing.Size(100, 20)
		Me.TextBox36.TabIndex = 0
		'
		'Panel13
		'
		Me.Panel13.Controls.Add(Me.TextBox37)
		Me.Panel13.Controls.Add(Me.TextBox38)
		Me.Panel13.Controls.Add(Me.TextBox39)
		Me.Panel13.Location = New System.Drawing.Point(238, 120)
		Me.Panel13.Name = "Panel13"
		Me.Panel13.Size = New System.Drawing.Size(200, 100)
		Me.Panel13.TabIndex = 5
		'
		'TextBox37
		'
		Me.TextBox37.Location = New System.Drawing.Point(4, 56)
		Me.TextBox37.Name = "TextBox37"
		Me.TextBox37.Size = New System.Drawing.Size(100, 20)
		Me.TextBox37.TabIndex = 2
		'
		'TextBox38
		'
		Me.TextBox38.Location = New System.Drawing.Point(4, 30)
		Me.TextBox38.Name = "TextBox38"
		Me.TextBox38.Size = New System.Drawing.Size(100, 20)
		Me.TextBox38.TabIndex = 1
		'
		'TextBox39
		'
		Me.TextBox39.Location = New System.Drawing.Point(4, 4)
		Me.TextBox39.Name = "TextBox39"
		Me.TextBox39.Size = New System.Drawing.Size(100, 20)
		Me.TextBox39.TabIndex = 0
		'
		'Panel14
		'
		Me.Panel14.Controls.Add(Me.TextBox40)
		Me.Panel14.Controls.Add(Me.TextBox41)
		Me.Panel14.Controls.Add(Me.TextBox42)
		Me.Panel14.Location = New System.Drawing.Point(32, 120)
		Me.Panel14.Name = "Panel14"
		Me.Panel14.Size = New System.Drawing.Size(200, 100)
		Me.Panel14.TabIndex = 7
		'
		'TextBox40
		'
		Me.TextBox40.Location = New System.Drawing.Point(4, 56)
		Me.TextBox40.Name = "TextBox40"
		Me.TextBox40.Size = New System.Drawing.Size(100, 20)
		Me.TextBox40.TabIndex = 2
		'
		'TextBox41
		'
		Me.TextBox41.Location = New System.Drawing.Point(4, 30)
		Me.TextBox41.Name = "TextBox41"
		Me.TextBox41.Size = New System.Drawing.Size(100, 20)
		Me.TextBox41.TabIndex = 1
		'
		'TextBox42
		'
		Me.TextBox42.Location = New System.Drawing.Point(4, 4)
		Me.TextBox42.Name = "TextBox42"
		Me.TextBox42.Size = New System.Drawing.Size(100, 20)
		Me.TextBox42.TabIndex = 0
		'
		'Panel15
		'
		Me.Panel15.Controls.Add(Me.TextBox43)
		Me.Panel15.Controls.Add(Me.TextBox44)
		Me.Panel15.Controls.Add(Me.TextBox45)
		Me.Panel15.Location = New System.Drawing.Point(238, 14)
		Me.Panel15.Name = "Panel15"
		Me.Panel15.Size = New System.Drawing.Size(200, 100)
		Me.Panel15.TabIndex = 6
		'
		'TextBox43
		'
		Me.TextBox43.Location = New System.Drawing.Point(4, 56)
		Me.TextBox43.Name = "TextBox43"
		Me.TextBox43.Size = New System.Drawing.Size(100, 20)
		Me.TextBox43.TabIndex = 2
		'
		'TextBox44
		'
		Me.TextBox44.Location = New System.Drawing.Point(4, 30)
		Me.TextBox44.Name = "TextBox44"
		Me.TextBox44.Size = New System.Drawing.Size(100, 20)
		Me.TextBox44.TabIndex = 1
		'
		'TextBox45
		'
		Me.TextBox45.Location = New System.Drawing.Point(4, 4)
		Me.TextBox45.Name = "TextBox45"
		Me.TextBox45.Size = New System.Drawing.Size(100, 20)
		Me.TextBox45.TabIndex = 0
		'
		'Panel16
		'
		Me.Panel16.Controls.Add(Me.TextBox46)
		Me.Panel16.Controls.Add(Me.TextBox47)
		Me.Panel16.Controls.Add(Me.TextBox48)
		Me.Panel16.Location = New System.Drawing.Point(32, 14)
		Me.Panel16.Name = "Panel16"
		Me.Panel16.Size = New System.Drawing.Size(200, 100)
		Me.Panel16.TabIndex = 4
		'
		'TextBox46
		'
		Me.TextBox46.Location = New System.Drawing.Point(4, 56)
		Me.TextBox46.Name = "TextBox46"
		Me.TextBox46.Size = New System.Drawing.Size(100, 20)
		Me.TextBox46.TabIndex = 2
		'
		'TextBox47
		'
		Me.TextBox47.Location = New System.Drawing.Point(4, 30)
		Me.TextBox47.Name = "TextBox47"
		Me.TextBox47.Size = New System.Drawing.Size(100, 20)
		Me.TextBox47.TabIndex = 1
		'
		'TextBox48
		'
		Me.TextBox48.Location = New System.Drawing.Point(4, 4)
		Me.TextBox48.Name = "TextBox48"
		Me.TextBox48.Size = New System.Drawing.Size(100, 20)
		Me.TextBox48.TabIndex = 0
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(479, 261)
		Me.Controls.Add(Me.TabControl1)
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.TabControl1.ResumeLayout(False)
		Me.TabPage1.ResumeLayout(False)
		Me.TabPage2.ResumeLayout(False)
		Me.TabPage3.ResumeLayout(False)
		Me.TabPage4.ResumeLayout(False)
		Me.Panel1.ResumeLayout(False)
		Me.Panel1.PerformLayout()
		Me.Panel2.ResumeLayout(False)
		Me.Panel2.PerformLayout()
		Me.Panel3.ResumeLayout(False)
		Me.Panel3.PerformLayout()
		Me.Panel4.ResumeLayout(False)
		Me.Panel4.PerformLayout()
		Me.Panel5.ResumeLayout(False)
		Me.Panel5.PerformLayout()
		Me.Panel6.ResumeLayout(False)
		Me.Panel6.PerformLayout()
		Me.Panel7.ResumeLayout(False)
		Me.Panel7.PerformLayout()
		Me.Panel8.ResumeLayout(False)
		Me.Panel8.PerformLayout()
		Me.Panel9.ResumeLayout(False)
		Me.Panel9.PerformLayout()
		Me.Panel10.ResumeLayout(False)
		Me.Panel10.PerformLayout()
		Me.Panel11.ResumeLayout(False)
		Me.Panel11.PerformLayout()
		Me.Panel12.ResumeLayout(False)
		Me.Panel12.PerformLayout()
		Me.Panel13.ResumeLayout(False)
		Me.Panel13.PerformLayout()
		Me.Panel14.ResumeLayout(False)
		Me.Panel14.PerformLayout()
		Me.Panel15.ResumeLayout(False)
		Me.Panel15.PerformLayout()
		Me.Panel16.ResumeLayout(False)
		Me.Panel16.PerformLayout()
		Me.ResumeLayout(False)

	End Sub
	Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
	Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
	Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
	Friend WithEvents Panel13 As System.Windows.Forms.Panel
	Friend WithEvents TextBox37 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox38 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox39 As System.Windows.Forms.TextBox
	Friend WithEvents Panel14 As System.Windows.Forms.Panel
	Friend WithEvents TextBox40 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox41 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox42 As System.Windows.Forms.TextBox
	Friend WithEvents Panel15 As System.Windows.Forms.Panel
	Friend WithEvents TextBox43 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox44 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox45 As System.Windows.Forms.TextBox
	Friend WithEvents Panel16 As System.Windows.Forms.Panel
	Friend WithEvents TextBox46 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox47 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox48 As System.Windows.Forms.TextBox
	Friend WithEvents Panel9 As System.Windows.Forms.Panel
	Friend WithEvents TextBox25 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox26 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox27 As System.Windows.Forms.TextBox
	Friend WithEvents Panel10 As System.Windows.Forms.Panel
	Friend WithEvents TextBox28 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox29 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox30 As System.Windows.Forms.TextBox
	Friend WithEvents Panel11 As System.Windows.Forms.Panel
	Friend WithEvents TextBox31 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox32 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox33 As System.Windows.Forms.TextBox
	Friend WithEvents Panel12 As System.Windows.Forms.Panel
	Friend WithEvents TextBox34 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox35 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox36 As System.Windows.Forms.TextBox
	Friend WithEvents TabPage3 As System.Windows.Forms.TabPage
	Friend WithEvents Panel5 As System.Windows.Forms.Panel
	Friend WithEvents TextBox13 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox14 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox15 As System.Windows.Forms.TextBox
	Friend WithEvents Panel6 As System.Windows.Forms.Panel
	Friend WithEvents TextBox16 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox17 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox18 As System.Windows.Forms.TextBox
	Friend WithEvents Panel7 As System.Windows.Forms.Panel
	Friend WithEvents TextBox19 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox20 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox21 As System.Windows.Forms.TextBox
	Friend WithEvents Panel8 As System.Windows.Forms.Panel
	Friend WithEvents TextBox22 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox23 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox24 As System.Windows.Forms.TextBox
	Friend WithEvents TabPage4 As System.Windows.Forms.TabPage
	Friend WithEvents Panel4 As System.Windows.Forms.Panel
	Friend WithEvents TextBox10 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox11 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox12 As System.Windows.Forms.TextBox
	Friend WithEvents Panel3 As System.Windows.Forms.Panel
	Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox8 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox9 As System.Windows.Forms.TextBox
	Friend WithEvents Panel2 As System.Windows.Forms.Panel
	Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
	Friend WithEvents Panel1 As System.Windows.Forms.Panel
	Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
	Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

End Class

Open in new window

Produces the following output -First tab page.  Each tab page is similar.  Panels with text box's in each.And the following file is generated -Capture.JPG-saige-
0
it_saigeDeveloperCommented:
Or you could do what Eric recommended.

@Eric - I was not aware of that method.  ;)

-saige-
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Here's another option to recursively search via Iterator/Yield if you have VS2012 or above:
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For Each txtBox In GetTextBoxes(Me)
            Debug.Print(String.Format("{0}: {1}", txtBox.Name, txtBox.Text.Trim))
            ' outputFile.wplWriteLine(txtBox.Name, txtBox.Text.Trim)
        Next
    End Sub

    Private Iterator Function GetTextBoxes(ByVal cont As Control) As IEnumerable(Of TextBox)
        For Each ctl As Control In cont.Controls
            If TypeOf ctl Is TextBox Then
                Yield ctl
            ElseIf ctl.HasChildren Then
                For Each TB In GetTextBoxes(ctl)
                    Yield TB
                Next
            End If
        Next
    End Function

End Class

Open in new window

1
Mike TomlinsonMiddle School Assistant TeacherCommented:
Be aware that GetNextControl() only returns controls that have TabStop set to True (which it normally is for TextBoxes, though it could be turned off for whatever reason).
0
taviafAuthor Commented:
@Mike Tomlinson,
The GetNextControl() works great at this point. But you say if TabStop was set to false that the function would not work? I assume the function you have include does work if TabStop is, some how, set to false?!?!
0
it_saigeDeveloperCommented:
Correct, his implementation does not look at the TabStop to determine if the control is returned (although it could).

-saige-
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You'd only change TabStop to False if you don't want that Control to be visited when the user hits the Tab key.  That's not normally the case for a TextBox, but it is possible.  Just wanted to make you aware of that caveat.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.