学生信息管理系统——简单解决登录次数问题

做学生管理系统第一步就是登录窗体,然而好些人犯了难,登录次数三次就会弹窗,无论输对输错,那么一个简单的方法帮助大家解决问题。

Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long
Public OK As Boolean
Dim miCount As Integer                   
Dim YZ As Integer            '每登录错误一次,YZ值+1


----------


Private Sub Cmd_ok_Click()
    Dim txtSQL As String
    Dim mrc As ADODB.Recordset
    Dim MsgText As String
    Dim UserName As String
    miCount = miCount + 1                 '每点击一次登录,micount值+1
    UserName = ""
   If Trim(Txt_yhm.Text = "") Then
        MsgBox "请输入用户名!", vbOKOnly + vbExclamation, "警告"
        YZ = YZ + 1                    '错误处:空用户名,YZ+1
        Txt_yhm.SetFocus
    Else
        txtSQL = "select * from user_Info where user_ID = '" & Txt_yhm & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
        If mrc.EOF Then
            MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
            YZ = YZ + 1                '错误处:无用户名,YZ+1
            Txt_yhm.SetFocus
        Else
            If Trim(mrc.Fields(1)) = Trim(Txt_Mm.Text) Then
                MFrm_Main.Show         '账号密码都正确,直接进入。
                OK = True
                mrc.Close
                Me.Hide
                UserName = Trim(Txt_yhm.Text)
            Else
                MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
                YZ = YZ + 1             '错误处:密码错误,YZ+1
                Txt_Mm.SetFocus
                Txt_Mm.Text = ""
            End If
        End If
    End If

    If miCount = 3 Then                 '当点击登录按钮三次的时候
        If miCount = YZ Then            '如果,登录次数=错误次数
            MsgBox "!", vbOKOnly + vbExclamation, "警告"
            Me.Hide                     '窗体隐藏
            'Unload Me                  '或者卸载
        Else                            '此处意思为:当点击登录按钮三次,错误次数不是三次(即第三次输入正确),就显示主窗体。
            MFrm_Main.Show
        End If
    End If

    Exit Sub
End Sub

新人第一篇博客,求高手指点,欢迎诸位留言。

你可能感兴趣的:(VB语言)