[Student information management system] restrictions on textbox

Source: Internet
Author: User
Tags delete key

The input box in the student information management system must be limited. Just as we have never seen anyone whose name is a number. In addition, the interface also needs to be associated with the background database. We cannot set the length of the input box to be greater than the length of the field specified by the database.

The restriction on the input box is implemented through the keypress event of Textbox, and the effect is achieved by limiting the ASCII code value corresponding to the key on the keyboard. Ensure that the backspace and Delete keys are available in each input box for modification.

Student ID: we can only limit it to numbers.

Private sub txtsid_keypress (keyascii as integer) If keyascii = 8 then exit sub <span style = "white-space: pre "> </span> 'The backspace key can be used if keyascii = 127 then exit sub <span style =" white-space: pre "> </span> 'delete key is available if keyascii> 48 and keyascii <57 then <span style =" white-space: pre "> </span> 'else <span style =" white-space: pre "> </span> msgbox" student ID, enter a number ", vbokonly + vbexclamation, "Warning" <span style = "white-space: pre"> </span> 'when the input is not a number, the system prompts keyascii = 0 txtsid. selstart = 0 txtsid. sellength = Len (txtsid. text) <span style = "white-space: pre"> </span> 'select the end ifend sub content in the input box.
Name: Only letters or Chinese characters can be entered in this box.

Private sub txtname_keypress (keyascii as integer) if (keyascii <0) or (keyascii> = 65 and keyascii <= 90) or (keyascii> = 97 and keyascii <= 122) or (keyascii = 8) then else msgbox "name consists of letters and Chinese characters", vbokonly + vbexclamation, "warning" keyascii = 0 txtname. selstart = 0 txtname. sellength = Len (txtname. text) end if end sub
Admission date: The format is yyyy-mm-dd. Therefore, in addition to ensuring that only numbers are allowed, the ASCII value corresponding to the symbol must be displayed.
Private sub txtborndate_keypress (keyascii as integer) If keyascii = 8 then exit sub if keyascii = 127 then exit sub if keyascii = 45 then exit sub <span style = "white-space: pre "> </span> 'ascii value corresponding to the '-' If keyascii <48 or keyascii> 57 then msgbox" Date of birth, enter a number ", vbokonly + vbexclamation, "Warning" keyascii = 0 txtborndate. selstart = 0 txtborndate. sellength = Len (txtborndate. text) end ifend sub
Contact number: we also need to set the length of the contact number, which cannot exceed 11 characters. This is achieved through the Chang affair of textbox.

Private sub txttel_change () txttel. maxlength = 11 <span style = "white-space: pre"> </span> 'the maximum length is 11-bit end sub.

Through the free deformation, the restrictions on the input boxes in the entire student information management system were set. At the beginning, I just knocked out the code and did not think about it. After the acceptance, all the problems were revealed. From the perspective of a user, the people are welcome to serve the people wholeheartedly.







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.