I am still struggling with Classes.
In the past (Access Basic) I put some functions in a Module that would verify entries in text boxes on a Form.
I now understand that to comply with good OOP practice these validations should be preserved as a Class.
So I now have a class as follows
Public Class Validations1
Public Shared Function CheckLength(ByVal strString As String, _
ByVal Length As Integer) As Boolean
If Len(strString) > Length Then
MsgBox("Too many characters")
This is called from any form in my project as follows.
Private Sub TxbHQPhone_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles TxbHQPhone.Validating
If Validations1.CheckLength(TxbHQPhone.Text, 11) = False Then e.Cancel = True
The code works, but is this the correct way of doing this type of operation?
It’s the “Public Shared Function” bit that I am mainly concerned about
I know that I could set the “MaxLength” of the text box to what ever I wanted. This is just an example.