You could also use LINQ:
Dim empty =
Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0)
If empty.Any Then
MessageBox.Show(String.Format("Please fill following textboxes: {0}",
String.Join(",", empty.Select(Function(txt) txt.Name))))
End If
The interesting method is Enumerable.OfType
The same in query syntax(more readable in VB.NET):
Dim emptyTextBoxes =
From txt In Me.Controls.OfType(Of TextBox)()
Where txt.Text.Length = 0
Select txt.Name
If emptyTextBoxes.Any Then
MessageBox.Show(String.Format("Please fill following textboxes: {0}",
String.Join(",", emptyTextBoxes)))
End If
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…