Results 1 to 9 of 9

Thread: Restrict to 3 retries (password boxes)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    16

    Restrict to 3 retries (password boxes)

    Code:
    Dim IdCorrect As Boolean
    Dim Attempts As Integer
    
    Private Sub cmdEnter_Click()
    Attempts = 0
    
    If txtUser = "HornsbyB" And txtPass = "abcde" Then
    IdCorrect = True
    Form2.Visible = True
    Login.Visible = False
    'closes login screen and opens main program
    ElseIf txtUser = "ClaptonN" And txtPass = "fghij" Then
    IdCorrect = True
    Form2.Visible = True
    Login.Visible = False
    ElseIf txtUser = "ZeppelinF" And txtPass = "klmno" Then
    IdCorrect = True
    Form2.Visible = True
    Login.Visible = False
    If IdCorrect = False Then Attempts = Attempts + 1
    'if the user gets the username or password wrong the value adds 1 attempt
    End If
    If Attempts = 3 Then
        MsgBox "No more attempts"
        End
        End If
    The aim of this code is to block the user and end the program when the user has made 3 attempts. When I run the program it does not register any of the attempts to close it. My friend has done the same thing but using a text box value rather than storing it so the text box adds 1 to its value each time. This seems to work. What am I doing wrong? As I see it its exactly the same process but storing it as a physical value rather than a integer.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    You are reseting Attempts each time the command button is clicked

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    16

    Talking

    lolz so I am. Just need to put attempts = 0 on form load then. Thx for help

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Or make it a static variable


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    And/or unload the form from memory so you don't need to reset the Attempts variable to zero each time.

  6. #6
    End is a ver ybad way to end your program, it can cause loads of memory leakage

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Ah, yes, didn't notice it there. Unload the forms and set them to nothing:

    VB Code:
    1. Dim MyForm As Form
    2.     For Each MyForm In Forms
    3.         Unload MyForm
    4.         Set MyForm = Nothing
    5.     Next MyForm

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    16

    Re: Restrict to 3 retries (password boxes)

    Tried putting the attempts = 0 on form load but still nothing happens when I click enter...help

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    16

    Re: Restrict to 3 retries (password boxes)

    Quote Originally Posted by c4ss
    Tried putting the attempts = 0 on form load but still nothing happens when I click enter...help
    Ignore that, worked it out myself, too early lol.

    Needed to end if after attempts +1 then start a new If statement for the message box.

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