Original code: If txtschool. Text = "" then
Msgbox "Enter the registration unit! ", Vbinformation
Checkregtext = false
Txtschool. setfocus
Exit Function
End if
1: Len (txtschool. Text) is much faster than txtschool. Text =.
2: Add trim to txtschool. Text
3: remove the TXT school repetition.
Result:
1: stringisempty function 'determines whether the string length is null
Public Function stringisempty (byref sstring as string) as Boolean
Sstring = trim (sstring)
Stringisempty = Len (sstring) = 0
End Function
2: The textboxisempty function 'text box is empty.
Private function textboxisempty (otextbox as Textbox, smessage as string) as Boolean
If stringisempty (otextbox. Text) then
Msgbox smessage, vbinformation
Otextbox. setfocus
Textboxisempty = true
End if
End Function
3: Final Result: If textboxisempty (txtperson, "Enter the registrant! ") Then exit function
If textboxisempty (txtconn, "Enter the contact number! ") Then exit function
If textboxisempty (txtschool, "Enter the registration unit! ") Then exit function