title: creating a VB.Net class method that can validate form controls
body: <p>I would like to create a VB.Net class method that validates data entered by user on a form. I would like to be in a position to call this method from all my forms in my code. I would like to achieve this by creating a method that loop through all the Listbox and Textboxes on a form making sure that is not empty and if its empty give user another chance to enter valid data. This is working on every form as subprocedure, however I do have four forms and I would like to write the code once and call it from all my four forms.</p>
  
  <p>MY QUESTION is then why do I get an error message "Controls is not declared or it may be inaccessible due to its protection level" when I code like below on my For Each loop:</p>
  
  <pre><code>Public Class formsValidationClass
  
      Public Function validate()
  
          'validation happens here for either a List Box or Text
          For Each ctrl As Control In Controls
              If TypeOf ctrl Is TextBox Or TypeOf ctrl Is ListBox Then
              End If
          Next 'form validation ends here
      End Function
  
  End Class
  </code></pre>