This Visual Basic code defines event handlers for a login form with OK and Cancel buttons. It checks the user-entered ID and password against valid credentials, clearing and tracking failed attempts. If failures reach 3, access is denied and the application exits.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
30 views
Exercise 9
This Visual Basic code defines event handlers for a login form with OK and Cancel buttons. It checks the user-entered ID and password against valid credentials, clearing and tracking failed attempts. If failures reach 3, access is denied and the application exits.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
Exercise 9
Public Class Form1
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Application.Exit() End Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Dim userID As String = Me.txtUserID.Text Dim password As String = Me.txtPassword.Text Static tries As Integer = 0 If userID = "user1" And password = "password1" Or userID = "user2" And password = "password2" Or userID = "user3" And password = "password3" Then MessageBox.Show("Your ID and Password are correct.") Application.Exit() ElseIf Not userID = "user1" And Not userID = "user2" And Not userID = "user3" And Not password = "password1" And Not password = "password2" And Not password = "password3" Then MessageBox.Show("Incorrect ID and Password.") Me.txtUserID.Clear() Me.txtPassword.Clear() tries += 1 ElseIf Not userID = "user1" And Not userID = "user2" And Not userID = "user3" Then MessageBox.Show("Incorrect ID.") Me.txtUserID.Clear() tries += 1 ElseIf Not password = "password1" And Not password = "password2" And Not password = "password3" Then MessageBox.Show("Incorrect password.") Me.txtPassword.Clear() tries += 1 End If If tries = 3 Then MessageBox.Show("Sorry, access denied.") Application.Exit() End If End Sub End Class