Determines whether the input information is empty.
In the data room charging system, we need to repeat the text box and the combo box to make sure that it is not empty. There are two conditions for this judgment: first, determines whether the combo box of all text boxes in the form is empty. The second type determines whether a part of the text box is empty. For card numbers and student numbers, we need to determine whether the user inputs a number. Almost every form needs to make a similar judgment, which is written one by one. I am familiar with the Code. However, this method does not seem so clever. At this time, we can define a class for judgment. The form using this function can directly call the method in the class. Next, let's briefly introduce how to implement it.
First, check whether all text boxes and combo boxes in the form are empty;
Imports System. windows. forms '************************************** * ******* 'file Name: verdict 'namespace: Ui' internal capacity: 'function: determines whether the user input is empty, and whether the input username and a series of text boxes are numbers' file relations: & apos; Author: Ding Guohua & apos; group: Baby scheduler; generated on: 10:32:09 & apos; version: V2.0 & apos; Modify log: & apos; Copyright: '*************************************** * ***** Public Class verdict '''''' Determines whether the input content of all text boxes and combo boxes in the form is empty. If there is a textbox or combo box that can be empty in the form, ''' cannot be used '''''''''
'''
Public Shared Function IsAllEmptyText (ByVal frm As Form) As Boolean Dim control As New Control For Each control In frm. controls 'traverse all Controls in the form If TypeOf control Is TextBox then' to determine whether the control Is a text box If control. text. trim = "" Then "determines whether the content of the text box is empty MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") control. focus () Return True Exit Function End If ElseIf TypeOf control Is ComboBox Then 'determines whether the control Is a combo box If control. text. trim = "" Then MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") Return True Exit Function End If Next Return False End Function
Then, judge whether some text boxes and combo boxes are empty;
'''''' Determines whether the Text attribute of the control in the control array is null '''''''''
'''
Public Shared Function IsSomeEmptyText (ByVal arrayControl () As Control) as Boolean Dim control As New Control For Each control In arrayControl 'traverses all elements In the array If TypeOf control Is TextBox then' to determine whether the control Is a text box If control. text. trim = "" Then "determines whether the content of the text box is empty MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") control. focus () Return True Exit Function End If ElseIf TypeOf control Is ComboBox Then 'determines whether the control Is a combo box If control. text. trim = "" Then MsgBox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") Return True Exit Function End If Next Return False End Function
Finally, determine whether it is a number;
'''''' Determine whether the input is a number '''''''''
'''
Public Shared Function IsNumberic (ByVal arrayControl () As Control) as Boolean Dim control As New Control For Each control In arrayControl 'traverses all elements In the array If TypeOf control Is TextBox then' to determine whether the control Is a TextBox 'if control. text. trim = "" then': determines whether the text box is empty. If IsNumeric (control. text) = False Then 'msgbox (control. tag. toString + "cannot be blank! ", VbOKOnly," tip ") MsgBox (control. tag. toString + "" + "enter a number", vbOKOnly, "prompt") control. focus () control. text = "" Return False Exit Function End If Next Return True End Function
Next, let's take the basic data settings in the data room charging system as an example to see how we call them;
Dim arrayControl() As Control ReDim Preserve arrayControl(4) arrayControl(0) = txtRate arrayControl(1) = txtUnittime arrayControl(2) = txtLeasttime arrayControl(3) = txtPretime arrayControl(4) = txtLimitcash If verdict.IsSomeEmptyText(arrayControl) Then Exit Sub End If If verdict.IsNumberic(arrayControl) = False Then Exit Sub End If
Abstract The public part and write it into a class. The other forms are called directly, which is convenient and simple. The second version of the data center charging system is not complete and will be continued ......