|
-
Dec 2nd, 2004, 08:57 AM
#1
Thread Starter
Junior Member
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.
-
Dec 2nd, 2004, 09:45 AM
#2
You are reseting Attempts each time the command button is clicked
-
Dec 2nd, 2004, 09:52 AM
#3
Thread Starter
Junior Member
lolz so I am. Just need to put attempts = 0 on form load then. Thx for help
-
Dec 2nd, 2004, 09:56 AM
#4
-
Dec 2nd, 2004, 10:03 AM
#5
And/or unload the form from memory so you don't need to reset the Attempts variable to zero each time.
-
Dec 2nd, 2004, 10:41 AM
#6
Banned
End is a ver ybad way to end your program, it can cause loads of memory leakage
-
Dec 2nd, 2004, 11:03 AM
#7
Ah, yes, didn't notice it there. Unload the forms and set them to nothing:
VB Code:
Dim MyForm As Form
For Each MyForm In Forms
Unload MyForm
Set MyForm = Nothing
Next MyForm
-
Dec 3rd, 2004, 04:20 AM
#8
Thread Starter
Junior Member
Re: Restrict to 3 retries (password boxes)
Tried putting the attempts = 0 on form load but still nothing happens when I click enter...help
-
Dec 3rd, 2004, 04:23 AM
#9
Thread Starter
Junior Member
Re: Restrict to 3 retries (password boxes)
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|