In: Computer Science
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes.
THANKS
Program:
Sub createPassword()
Dim password As String
Dim correctPassword As String
Dim i, p As Integer
' assume the correct password is 12345
correctPassword = 12345
For i = 1 To 3
'accepting the passwords
password = InputBox("Enter your password: ")
'comparing the correct password and user password, if it's true
then return 0
p = StrComp(correctPassword, password)
If (p = 0) Then
'saving and closing workbook for correct password
ThisWorkbook.Saved = True
Application.Quit
Exit For
End If
If (i = 3) Then
MsgBox ("You have exceeded 3 attempts! Try next time")
End If
Next i
End Sub
Private Sub CommandButton1_Click()
createPassword
End Sub
Output: