尝试离开连续倒数

时间:2018-11-05 05:49:01

标签: excel vba

是否可以继续尝试?像在iPhone上一样,您可以先尝试一下,然后再禁用它。如果您再次锁定手机并尝试输入错误的密码,它将继续使用先前的尝试号码。例如,在下面的这段代码中,我将计数器设置为5次尝试。然后用户决定输入两次错误的密码,然后放弃一会儿再尝试。即使用户取消了尝试,现在的尝试次数也应该为3。直到输入正确的密码,然后将其重置为5。有什么办法可以这样做?谢谢。

Private Sub ToggleButton1_Click()
Dim x, z As String
Dim counter As Integer
Dim mcounter As Integer
Dim attempts As Integer
counter = 5
attempts = 0

If ToggleButton1 = True And Sheet2.Range("J11") = "Status: UNLOCKED" Then
Sheet2.ToggleButton1 = False
GoTo looy
ElseIf ToggleButton1 = False Then
On Error GoTo ending
Sheet2.Range("I11") = "Status: LOCKED"
Sheet2.Range("I11").Interior.ColorIndex = 3
Sheet2.Protect "3mice"
Exit Sub
End If

Do Until x = "3mice"
looy:
x = InputBox("Please enter password", "FOR ADMIN USE ONLY")
If x = "" Then
Sheet2.ToggleButton1 = False
Exit Sub
End If
If x = "3mice" Then
Sheet2.Unprotect password:="3mice"
Sheet2.Range("I11").Interior.ColorIndex = 4
Range("I11") = "Status: UNLOCKED"
Exit Sub
End If
If x <> "3mice" Then
If counter > 1 Then
mcounter = mcounter - 1
counter = counter - 1
attempts = attempts + 1
ElseIf counter = 1 Or mcounter = 1 Then
GoTo disable
End If
z = MsgBox("Wrong Password", vbOKCancel + vbExclamation, "Error")
Select Case z
Case vbOK
GoTo looy
Case vbCancel
mcounter = counter - attempts
GoTo ending
End Select
End If
disable:
MsgBox "Disabled for 10 seconds.", vbCritical + vbOKOnly
Application.Wait (Now + TimeValue("0:00:10"))
counter = 1


Loop
ending:
Sheet2.ToggleButton1 = False

End Sub

0 个答案:

没有答案