If you would like to get a list of TextBoxes, which name is
txtBoxN
(where
N
is a number) and TextBox is not empty, then try this:
Dim pattern As String = "^txtBox\d$"
Dim r As Regex = New Regex(pattern)
Dim notEmptyTextBoxes = Me.Controls.OfType(Of TextBox) _
.Where(Function(x) x.Text.Trim.Length > 0 And r.Match(x.Name).Success) _
.ToList()
For Each tb As TextBox In notEmptyTextBoxes
MsgBox(String.Format("{0} {1}", tb.Name, tb.Text))
Next
If you would like to inform a user about textboxes to fill, try this:
Dim msg = String.Join("; ", Me.Controls.OfType(Of TextBox) _
.Where(Function(x) x.Text.Trim.Length = 0 And r.Match(x.Name).Success) _
.Select(Function(x) x.Name) _
.ToList())
MsgBox("Please, fill the following textboxes: " & vbCr & _
msg, MsgBoxStyle.Information, "Information")