Determines whether the text box is empty.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.