[Data Center reconstruction] Small and understandable

Source: Internet
Author: User

When writing the data room student registration function, I encountered some minor problems. Just like the "Sparrow is small and dirty", although the problem is small, I don't have to fully understand its logical process, the following is a summary to facilitate future use and further study.

First, let's take a look at the student registration process: when you enter the card number, you can search for it to determine whether the card number exists, and enter it again; otherwise, you can continue to enter the information. When you click "save", first check whether the student ID exists. If the student ID already exists, the system prompts you to re-enter the student ID. If the student ID does not exist, the system prompts that the registration is successful.

Of course, this is what I understand. Each person's understanding is somewhat different.

During the design, three methods are displayed in layer D: search, insert, and judge. In layer B, you must first check whether the card number exists, and then determine whether the student number exists before inserting it. This indicates that the judgment method is used in the insert method.

After learning about the process, let's take a look at how these three methods are written in layer B. First, we can define the insert and judgment methods, and directly use the judgment in the insert.

Second, define the judgment method as a private method and call this private method in the insert method. Let's take a look at the second type of code:

Public sub insertstudentinfodal (byval enstudentinfo as entity. enstudentinfo) 'execute the insert statement. The parameter enstudentinfo defined here applies to dim dinfo as Dal throughout the method. registerdal dim isexist as Boolean defines a Boolean variable to determine whether isexist = querystudentno (enstudentinfo. studentno) 'the private method defined here is called.
If isexist = true then' if the value is true, the registration is successful. dinfo = New DAL. registerdal () dinfo. insertdal (enstudentinfo) msgbox ("registration successful! ") End if end sub
Private function querystudentno (byval studentno as string) as Boolean 'defines a private method and calls dim dinfo as Dal in other methods. registerdal dim einfo as new entity. enstudentinfo dinfo = new Dal. registerdal () einfo = dinfo. querystudentno (studentno) if not einfo is nothing then 'determines whether the student ID is repeated msgbox ("student ID is repeated, please enter it again! ") Return false end if return true end Function
In the above Code, the return value of the private method querystudentno is defined as boolean. When the insertstudentinfodal method needs to call it, define a Boolean variable isexist to accept the return value of querystudentno, and then determine whether to return the result by judging whether isexist is true.

The above two methods have no major changes, but the second method is defined as private. When multiple methods need to use this method, this method shows its advantages.

During data center reconstruction, I sometimes don't understand it, and sometimes I don't know how to write it. Sometimes it is written, but you don't understand it. Is progress ,,

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.