|
-
March 6th, 2002, 10:31 AM
#1
Loops
Hi there,
I am quite new to VB and I am trying to write a loop in my program that allows you to have five attempts in getting the password correct, after which it will exit you.
Can someone please show me how this can be done using:
1) Do-While loop.
2) For loop.
3) Any other method
Any help will be appreciated.
Thank you in advance.
I have included below the code that I have been trying to use, but it does not work.
Private Sub CmdValid_Click()
'This procedure checks the input password
Dim Response As Integer
Do
If txtPassword.Text = txtPassword.Tag Then
'If correct, display message box
MsgBox "You've passed security!", vbOKOnly + vbExclamation, "Access Granted"
Else
'If incorrect, give option to try again
Response = MsgBox("Incorrect password", vbRetryCancel + vbCritical, "Access Denied")
End If
If Response = vbRetry Then
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
Response = Response + 1
lblCounter.Caption = Response
Print Response
Else
End
End If
txtPassword.SetFocus
Loop While Response < 5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|