One of the computer room systems

Introduction to the login interface

From the current point of view, all the login interfaces are similar, and they all require a user name and password. Of course, the login interface of WeChat is special, and WeChat is scanned as a QR code to log in. WeChat currently does not support account and password login ( 2017.12.22 ).

Today I mainly talk about the login interface when VB is used as a computer room. Like the traditional login interface, a user name and password are required to log in. The interface design is shown in the following figure:

A very classic login interface, but someone asked me why there is this cancel button? Everyone can think about this question. You can think about what kind of login interface you have seen, and what are the advantages of each? Why did the designer design it like this? There is a lot of knowledge in it. I hope people who read this article can attach great importance to.

The answer I gave to this cancel button is: I don't know the user name and password while the software is running, and it happens that my mouse can't be used. What should I do if I want to exit this interface? If there is this button, you can switch and exit the interface through the tab key of the keyboard. Maybe the designer has other intentions, but I haven't delved into it. I hope my friends can brainstorm this issue.

Let's talk about the problems encountered in writing code.

At first, there was no clue in my head, and I didn't know how to write this code. I can't take my mouth, just like there is a big durian in front of me, I can't take my mouth if I want to eat it. Because there was a small software for a student system before, so I used it for reference. Finally, the login window code of the computer room login system is made, and the specific code is as follows

Option Explicit
Public ok As Boolean
'Record the number of times
    Dim micount As Integer
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal Lpbuffer As String, Nsize As Long) As Long
Private Sub Command1_Click()
'Used to store SQL statements
   Dim txtSQL As String
   Dim mrc As ADODB.Recordset
'Used to store the recordset object
    Dim msgtext As String
    
     username = ""
     'Check if the input user name is empty
     If Trim(Text1.Text = "") Then
          MsgBox "There is no such user, please re-enter username!", vbOKOnly + vbExclamation, "Warning"
            Text1.SetFocus
             Else
                'Query the records of the specified user name
                  txtSQL = "select*from user_info where userid='" & Text1.Text & "'"
                      'Execute the query statement
                       Set mrc = ExecuteSQL(txtSQL, msgtext)
                            If mrc.EOF Then
                              MsgBox "There is no such user, please re-enter username!", vbOKOnly + vbExclamation, "Warning"
                                 Text1.SetFocus
                                 Else
                                  'Check if the entered password is correct
                                    If Trim(mrc.Fields(1)) = Trim(Text2.Text) Then
                                       ok = True
                                         mrc.Close
                                           Me.Hide
                                             username = Trim(Text1.Text)
                                             'FrmMain.Show
                                         Else
                                        MsgBox "Incorrect password, please try again!", vbOKOnly + vbExclamation, "Warning"
                                    
                                Text2.Text = ""
                                Text2.SetFocus
                          End If
            End If
    End If
        'Record the number of times the password was entered
         micount = micount + 1
           If micount = 3 Then
              MsgBox "The input error has reached 3 times, please check and log in again!", vbOKOnly + vbExclamation, "Warning"
              End
            End If
       ' Call main
        Exit Sub
End Sub

Private Sub Command2_Click()
   ok = False
   Me.Hide
End Sub

Private Sub Form_Load()
        Dim Sbuffer As String
        Dim Lsize As Long
        Sbuffer = Space$(255)
        Lsize = Len (Sbuffer)
        Call GetUserName(Sbuffer, Lsize) 'Prevent the existence of the last entered user name
        If Lsize > 0 Then
           Text1.Text = ""
            Else
           Text1.Text = vbNullString
        End If
        
        ok = False
        micount = 0
        
End Sub

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325991274&siteId=291194637