"System logon dialog box"

Source: Internet
Author: User


Frozen for three feet
"System logon dialog box"

A little bit of accumulation brings great progress. The system logon dialog box is the first small example I made with system edges. It can only be said that the name contains the word "system", although very simple, however, it is worth accumulating some details. This is because of the great progress that has been made by the accumulation.


Although the example is small, you can't save it at all. First, let's create a process for yourself.


Part 1
Create a database


Note:
Use the database function provided by VB to create a database.


Note: although the database is small and simple, you must pay attention to each step. Because it is just getting started with database applications, there may be problems somewhere.


Part 2
Form Design


Note: simple and skillful. Easy to complete


Note: The naming rules of controls are the most noteworthy. At this time, the real code writing has started. Although we are all watching it, the points of attention should not be vague.


Part 3
Create an ADO reference


Note: Do you really understand the truth.


Note:
If you don't understand it, you can understand it in practice.


Part 4
Write function code


Note: The code must be understood first and then typed


Note:
You need to understand the real connection, and do not feel that you understand it.


Part 5
Save the project and run the test.


Simply divide this small example into five parts, and then start to do it. It is not too difficult to create a database. I just think it is still a little unfamiliar, but the database is quickly created. There is nothing to do with the UI design industry, and it's okay to put a few controls, ADO
You can add a reference. Of course, the most difficult part is the code.


The code is divided into three parts: cancel the code of the button, confirm the code of the button, and then the code of a function created to verify the user name and password.


The cancel button code is the simplest part. The code of the function is complex and can be divided into the following parts: Create a database, execute the query command to obtain the user password, determine whether the query result is correct, and check whether the password is correct, close the database connection and release the object. The Code returned when the verification fails. In this example, you can easily write comments and then write the code below the comments. After the code is written, the comments will be deleted. When all the comments are deleted, the whole program has been quite clear. The following is the function code.

Privatefunction check_password (byval username as string, byval password as string) asbyte on error goto gperror dim objcn as new connection, objrs as newrecordset, strcn as string dim strsql as string objcn. connectionstring = "provider = Microsoft. jet. oledb.3.51; "&" Data Source = "& App. path & "\ database file \ systemload. mdb "objcn. open strsql = "select password from system user where username = '" & username & "'" set objrs. activeconnection = objcn objrs. open (strsql) If objrs. EOF then check_password = 0 else if password <> trim (objrs. fields ("password "). value) Then check_password = 1 else check_password = 2 end if objcn. close set objrs = nothing set objcn = nothing exit function gperror: check_password = 255 set objrs = nothing set objcn = nothing end Function

 


There is also a confirmation button. In fact, the structure is relatively simple, mainly to determine the meaning of the function return value to make clear instructions. The Code is as follows:

 

Privatesub cmdok_click () Static intlogtimes as integer dim intchecked as integer, strname asstring, strpassword as string intlogtimes = intlogtimes + 1 If intlogtimes> maxlogtimes then msgbox "exceeds allowed logon times" & vbcr _ & "the application will end", vbcritical, "Logon Verification" End else strname = trim (txtusername. text) strpassword = trim (txtpassword. text) Select case check_password (strname, strpassword) Case 0 msgbox "<" & strname & _ "> not a system user. Check whether the user name is entered correctly.", vbcritical, "Logon Verification" Case 1 msgbox "Password error, please enter", vbcritical, "Logon Verification" txtpassword = "" txtpassword. setfocus case 2 unload me load frmsplash. show case else msgbox "Logon Failed" is not completed normally. Please log on again. "& vbcrlf _ &" if you still cannot log on, please report to System Administrator ", vbcritical, "verify Logon" End select end ifend sub


Of course, it looks simple, and it looks like writing, which reflects a lot of problems. To sum up your next attention.


The first is the use of spaces. I don't know when I got into the habit of setting up spaces without any concerns, which brings me a lot of unnecessary trouble, some places or many spaces have no relationship, but some places cannot run without a space. The second is the naming problem. A good name is not determined by the length, but whether it really brings convenience to you. Don't figure it as soon as possible, it is inconvenient to use.
The naming of a brings a lot of unnecessary troubles to ourselves, especially when there are more and more controls or functions, how can we show our code to others? Once again, there is a format problem. If it is to be incorrect, the scale-down will be reduced, and the convenience it brings is self-evident.


After running the program, it will naturally be done. But before it is done, I have performed code debugging for a long time, but I have no experience at all. To write this article, I should take it as a precaution. This accumulation is the next 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.