+ Reply to Thread
Results 1 to 7 of 7

Password - 3 chances and **off

  1. #1
    Registered User
    Join Date
    11-05-2005
    Posts
    10

    Arrow Password - 3 chances and **off

    I have put together a macro for entering a password. How do I go about putting in a loop or some other ingenious bit of code so that you only get 3 chances before you get booted out.

    My code is attached to a very simple form and is as follows:

    Public Sub PasswordOK_Click()
    Dim Password As String
    Dim count As Integer
    Password = ""
    If TextBox1 = Password Then
    Personal_Details.Show
    Unload Me
    End If

    If TextBox1 <> Password Then
    TextBox1 = ""
    Label1.Visible = True
    PasswordOK.Visible = False
    PasswordCancel.Visible = False
    Application.Wait Now + TimeValue("00:00:02")
    Label1.Visible = False
    PasswordOK.Visible = True
    PasswordCancel.Visible = True
    End If
    End Sub
    Private Sub PasswordCancel_Click()
    Unload Me
    End Sub
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = vbFormControlMenu Then
    Cancel = True
    Beep
    End If
    End Sub

  2. #2
    Tushar Mehta
    Guest

    Re: Password - 3 chances and **off

    Before you get to the 3 chances bit, you have some more basic problems
    to address.

    Look at the code
    Password = ""
    If TextBox1 = Password Then

    Unless TextBox1 is empty your test will always fail since the expected
    password is the zero length string.

    Also, and depending on what you mean to do
    Personal_Details.Show
    Unload Me

    may not really be what you want. Instead, it might be more appropriate
    to use
    me.hide
    personal_details.show

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    >
    > I have put together a macro for entering a password. How do I go about
    > putting in a loop or some other ingenious bit of code so that you only
    > get 3 chances before you get booted out.
    >
    > My code is attached to a very simple form and is as follows:
    >
    > Public Sub PasswordOK_Click()
    > Dim Password As String
    > Dim count As Integer
    > Password = ""
    > If TextBox1 = Password Then
    > Personal_Details.Show
    > Unload Me
    > End If
    >
    > If TextBox1 <> Password Then
    > TextBox1 = ""
    > Label1.Visible = True
    > PasswordOK.Visible = False
    > PasswordCancel.Visible = False
    > Application.Wait Now + TimeValue("00:00:02")
    > Label1.Visible = False
    > PasswordOK.Visible = True
    > PasswordCancel.Visible = True
    > End If
    > End Sub
    > Private Sub PasswordCancel_Click()
    > Unload Me
    > End Sub
    > Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
    > Integer)
    > If CloseMode = vbFormControlMenu Then
    > Cancel = True
    > Beep
    > End If
    > End Sub
    >
    >
    > --
    > Shake
    > ------------------------------------------------------------------------
    > Shake's Profile: http://www.excelforum.com/member.php...o&userid=28577
    > View this thread: http://www.excelforum.com/showthread...hreadid=483069
    >
    >


  3. #3
    Registered User
    Join Date
    11-05-2005
    Posts
    10

    Password Protection

    I have put this in as an example as i did not want to show my password.

    Password = ""
    If TextBox1 = Password Then

    However we can assume that the code will read something like

    Password = "Bob"
    If TextBox1 = Password Then.

    I chose unload me so that if the code was eneted incorrectly or the cancel button is hit then the form does not load. Therefore the address book can not be accessed.

    Is there a bit of code for a three chances and then exit the form.

  4. #4
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Try below. However, if Excel is exited and re-opened, the user gets a new lease of lease for another 3 attempts.


    Public Sub PasswordOK_Click()
    Dim Password As String
    Dim count As Integer
    Static cnt


    cnt = cnt+1
    If cnt =3 Then Exit sub


    Password = "SESAME"
    If TextBox1 = Password Then
    Personal_Details.Show
    Unload Me
    End If

    If TextBox1 <> Password Then
    TextBox1 = ""
    Label1.Visible = True
    PasswordOK.Visible = False
    PasswordCancel.Visible = False
    Application.Wait Now + TimeValue("00:00:02")
    Label1.Visible = False
    PasswordOK.Visible = True
    PasswordCancel.Visible = True
    End If
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315

    New lease of life

    Try below. However, if Excel is exited and re-opened, the user gets a new lease of life for another 3 attempts.


    Public Sub PasswordOK_Click()
    Dim Password As String
    Dim count As Integer
    Static cnt


    cnt = cnt+1
    If cnt =3 Then Exit sub


    Password = "SESAME"
    If TextBox1 = Password Then
    Personal_Details.Show
    Unload Me
    End If

    If TextBox1 <> Password Then
    TextBox1 = ""
    Label1.Visible = True
    PasswordOK.Visible = False
    PasswordCancel.Visible = False
    Application.Wait Now + TimeValue("00:00:02")
    Label1.Visible = False
    PasswordOK.Visible = True
    PasswordCancel.Visible = True
    End If
    End Sub

  6. #6
    Registered User
    Join Date
    11-05-2005
    Posts
    10
    David M.

    That was an ingenious bit of coding. Thank you very much!!!!!!!!!!!!!!!!!!!!

  7. #7
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Shake,

    My pleasure. I was just having another look at the code. There is a small howler (which you probably picked up).

    If cnt =3 Then Exit sub should be If cnt >3 Then Exit sub.


    David

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1