机房收费系统——登录

版权声明:未经本人同意不得转载! https://blog.csdn.net/Hellen0708/article/details/82621189

前言

对机房系统有了宏观把控以后,可以开始登录窗体了。先别急着敲代码,先搞懂要满足什么功能。登录窗体要做到用户能成功登录,并且有三种权限的设置。了解了要满足的功能,要对思路进行梳理,制作流程图就可以帮我们很好的梳理思路。

这里写图片描述

部分代码展示

限制登录次数代码

miCount = miCount + 1
If miCount = 1 Then
    MsgBox "密码输入错误,您还有两次机会!", 48, "警告"
    txtPassword.SetFocus
    txtPassword.Text = ""
    Exit Sub
Else
    If miCount = 2 Then
        MsgBox "密码输入错误,您还有一次机会!", 48, "警告"
        txtPassword.SetFocus
        txtPassword.Text = ""
        Exit Sub
    Else
        If miCount = 3 Then
            MsgBox "密码输入错误,程序即将关闭!", 48, "警告"
            txtPassword.SetFocus
            txtPassword.Text = ""
            Me.Hide
            Exit Sub
        End If
    End If
End If

权限限制代码

If Trim(mrc.Fields(2)) = "一般用户" Then
   frmMain.userName.Enabled = True
   frmMain.opeMenu.Enabled = False
   frmMain.opeMenu.Visible = False
   frmMain.adminMenu.Enabled = False
   frmMain.adminMenu.Visible = False
End If

If Trim(mrc.Fields(2)) = "操作员" Then
    frmMain.userName.Enabled = True
    frmMain.opeMenu.Enabled = True
    frmMain.adminMenu.Enabled = False
    frmMain.adminMenu.Visible = False
End If

限制字符代码

Private Sub txtPassWord_KeyPress(KeyAscii As Integer)
    If KeyAscii > 31 And KeyAscii < 48 Or KeyAscii > 57 And KeyAscii < 65 Or KeyAscii > 90 And KeyAscii > 122 And KeyAscii < 127 Then
        MsgBox "不能输入特殊字符!", 48, "警告"
        KeyAscii = 0
    End If
End Sub

Private Sub txtUserName_KeyPress(KeyAscii As Integer)
    If KeyAscii > 31 And KeyAscii < 48 Or KeyAscii > 57 And KeyAscii < 65 Or KeyAscii > 90 And KeyAscii > 122 And KeyAscii < 127 Then
        MsgBox "不能输入特殊字符!", 48, "警告"
        KeyAscii = 0
    End If
End Sub

结语

登录窗体是比较容易的,虽然容易,还是先画流程图能让思路更加清晰哦!如果你的方法能让代码更少,欢迎交流!

猜你喜欢

转载自blog.csdn.net/Hellen0708/article/details/82621189