Dim PresenceCheck As Boolean 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 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()) PresenceCheck = False MsgBox("Please, fill the following textboxes: " & vbCr & _ msg, MsgBoxStyle.Information, "Information") If PresenceCheck = True Then Dim Filenum As Integer = FreeFile() FileOpen(Filenum, "C:\Users\Windows 7 User\Desktop\Customers.txt", OpenMode.Append) 'Text file is opened' PrintLine(Filenum, txtBox1.Text & "," & txtBox2.Text & "," & txtBox3.Text & "," & txtBox4.Text & "," & txtBox5.Text & "," & txtBox6.Text) 'The data entered in the above text boxes is combined together separated with commas and stored into the open text file' FileClose(Filenum) 'Once this is done the text file is closed and message below is displayed' MessageBox.Show("Customer has been successfully registered") End If