Determines whether the text box is empty.
There are often a lot of text boxes on the form that need to input information, some drop-down boxes need to be selected, for the input of this information, we always need to judge whether the input is empty, in the past, always one by one, this is too cumbersome, and one or two of them may be lost. Now let's easily determine whether the text box is empty.
'''''' Is used to determine whether the text box and drop-down box are empty ''''''
Module Module1 Public 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. tag. toString + "cannot be blank", vbOKOnly, "tip") control. focus () Return True Exit Function End If ElseIf TypeOf control Is ComboBox then' judgment If control. Text. Trim = "" Then MsgBox (control. Tag. ToString + "cannot be blank! ", VbOKOnly," tip ") Return False Exit Function End If Next Return False End FunctionEnd Module
Call the function:
Dim arrayControl() As Control ReDim Preserve arrayControl(5) arrayControl(0) = txtHourRate arrayControl(1) = txtHourTmpRate arrayControl(2) = txtLeastTime arrayControl(3) = txtLeastM arrayControl(4) = txtIncreaseTime arrayControl(5) = txtPrepareTime If IsSomeEmptyText(arrayControl) Then Exit Sub End If
Note:
MsgBox (control. Tag. ToString + "cannot be blank", vbOKOnly, "tip ")
The Tag attribute often forgets the value assignment. The value is usually assigned to label. text in front of the text box.