Results 1 to 2 of 2

Thread: Help with creating Excel VBA Password system

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2010
    Posts
    8

    Help with creating Excel VBA Password system

    Hi,

    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.
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Help with creating Excel VBA Password system

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width