vb.net room charge & Register text box empty prompt, one click empty text box all contents

Source: Internet
Author: User

has been the second time the computer room charge system reconfiguration, once again of course have to have the effect, as for the text box is empty hint method, review the first time room, those silly if statement let oneself to code of affinity degree greatly discount Ah! So what is the solution to those repetitive judgments? At this point we will refer to the so-called model form. In the model form, create an encapsulated array that can be simply called when a large number of text boxes in the form need to be judged as empty.

Create a new model class to store the parts of the public need.

1. Define a struct term, and encapsulate an array with the struct body

Public Structure term   ' definition struct term        Dim controlsub As Control        Dim strText as String        Sub New (ByVal Controlsub as Control, ByVal StrText as String)  ' Initialize object with            Me                . controlsub = Controlsub                . StrText = strt Ext            End With        end Sub

2. Define a term type array with struct

' defines a struct array of term type public    arraycontrol () as term

3. Function that determines whether a text box is empty

 "<summary > ' Determine if the text box is empty, and give the corresponding hint ' </summary> ' ' <param name= ' Arraycontrol ' ></param> ' <r Eturns></returns> ' <remarks></remarks> public Function cisempty (ByVal arraycontrol () as term As a Boolean Dim Termcontrol as term ' defines a term type variable ' to traverse all elements in the struct array, and if the control text is empty, prompt for each Termcon                 Trol in Arraycontrol ' iterates over all elements in the struct array if TypeOf termcontrol.controlsub is textbox and then ' determines whether the control is a text box If TermControl.controlSub.Text.Trim = "Then ' determines whether the text box content is empty MessageBox.Show (Termcont Rol.strtext & "Can't be empty!                    "," ", MessageBoxButtons.OK, Messageboxicon.exclamation) termControl.controlSub.Focus () ' Get focus Return True Exit Function End If 
4, of course, the function is written out, but also to the definition of the structure of the initialization of processing. We need to define a process Rdim () in the U layer of registe to complete this function

  Private Sub Rdim ()        ReDim Preserve Arraycontrol (9)  ' re-declaring array dimension        ' Initialize array        arraycontrol (0) = New term (txtcard , "card number")        Arraycontrol (2) = new Term (TXTSTUDENTNO, "study number")        Arraycontrol (3) = new Term (txtstudentname, "name")        Arraycontrol (4) = new Term (combosex, "gender")        Arraycontrol (5) = new Term (txtgrade, "grade")        Arraycontrol (6) = new term (Txtclass, "class")        Arraycontrol (7) = new Term (txtcash, "Amount")        Arraycontrol (8) = new Term (txtstatus, "comment")    End Sub
5, the preparation work done, the rest is a simple call! You can call the Cisempty function directly in the Register form.
Call Rdim ()    ' first calls the Rdim procedure for array initialization        ' calls the Cisemoty () function to detect if the input text box contents        if Cisempty (Arraycontrol) then            Exit Sub        End If
In this case, when the text box is empty, the system will automatically prompt, convenient and concise!

6, then how to achieve a key to clear the operation? Method is the same as judging the text box as empty, only need to write a clear function can be

  ' <summary> '    clear text box data ' ' </summary> ' '    <param name= ' Arraycontrol ' ></param >    ' <returns> return boolean,true</returns> ' '    <remarks></remarks> public    Function Allempty (ByVal arraycontrol () as term) as        a Boolean Dim termcontrol as term   ' defines a term type variable for each        ter Mcontrol in Arraycontrol            If TypeOf termcontrol.controlsub are TextBox then                termControl.controlSub.Text = "" c12/> ' determines the type of control, if it is a text box or combo box, the contents are emptied by the            End if        Next        Return True    Function
7. Then call:

Private Sub Btnclear_click (sender as Object, e as EventArgs) Handles Btnclear.click call        Rdim ()    ' First call the Rdim procedure for array initialization        ' call the Allemoty () function, delete the contents of the text box        If allempty (arraycontrol) then            Exit Sub        End If    end Sub
Although this is only described in the registration form, it is used for other text boxes and combo boxes, as long as the struct is initialized in the corresponding form and then called directly.

Feel:

Computer room charges are still in step-by-step, and the past is different from the so-called "feeling" has matured, at least when encountered problems when they will try to find the most simple and practical way to meet their needs.







vb.net room charge & Register text box empty prompt, one click empty text box all contents

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.