I am trying to create a password system in Excel using VBA. I need it to ask for the password, allow up to 3 attempts to enter the correct password which is "password", once the correct password is entered, I need it to ask for a 4 digit pin which needs to be entered one digit at a time and a message appears when each digit is entered to confirm the digit.
Also I need it to use a while loop in the coding.
I have attached my excel document. So far I have managed to make it enter the password allowing 3 attempts. But I do not know how to do the rest. Please help.
Here is some PIN code to start playing around with:
Code:
Dim counter As Integer
Dim myPin As String
Dim checkPin As String
Dim dontRun As Boolean
Private Sub TextBox1_Change()
If dontRun = False Then
counter = counter + 1
myPin = TextBox1.Text
Select Case counter
Case 1
checkPin = "1"
Case 2
checkPin = "12"
Case 3
checkPin = "123"
Case 4
checkPin = "1234"
Case Else
'no more
End Select
If myPin = checkPin Then
'continue
If counter = 4 Then
MsgBox "PIN Good!"
Exit Sub
End If
Else
dontRun = True
counter = counter - 1
MsgBox "WRONG!"
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
End If
Else
dontRun = False
End If
End Sub