title: Closing the app after a set number of attempts
body: <p>I've been working on a login program and want to close the app after 3 failed attempts. The passwords do come up as wrong but I think there is an issue with the counter. Here is all of my code so far:</p>
  <pre><code>Imports System.Data.OleDb
  Public Class frmMainScreen
      Dim provider As String
      Dim dataFile As String
      Dim ConnString As String
      Dim myConnection As OleDbConnection = New OleDbConnection
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
          provider = &quot;Provider = Microsoft.ACE.OLEDB.12.0;Data Source=&quot;
          dataFile = &quot;H:\Visual studio files\Project\CMPC\uDat.accdb&quot;
          ConnString = provider &amp; dataFile
          myConnection.ConnectionString = ConnString
          myConnection.Open()
  
          Dim userFound As Boolean = False
          Dim cmd As OleDbCommand = New OleDbCommand(&quot;SELECT * FROM uDat WHERE [username] = '&quot; &amp; txtUsername.Text &amp; &quot;'AND [password] = '&quot; &amp; txtPassword.Text &amp; &quot;'&quot;, myConnection)
          Dim dr As OleDbDataReader = cmd.ExecuteReader
  
          Dim username As String = &quot;&quot;
          Dim password As String = &quot;&quot;
          Dim attempts As Integer = 0
          While dr.Read
              userFound = True
              username = dr(&quot;Username&quot;).ToString
              password = dr(&quot;Password&quot;).ToString
          End While
  
          If userFound = True Then
              MsgBox(&quot;Welcome &quot; + username, MsgBoxStyle.Information)
              frmFilters3.Visible = False
              Me.Hide()
              frmFilters3.ShowDialog()
              myConnection.Close()
          ElseIf attempts = 3 Then
              MsgBox(&quot;You have reached the maximum tries. Please restart the app.&quot;, MsgBoxStyle.Critical)
          Else
              attempts = attempts + 1
              Me.Refresh()
              If myConnection.State = ConnectionState.Open Then
                  myConnection.Close()
              End If
              MsgBox(&quot;Username and password combination not found. 
  Please try again or click register.&quot;, MsgBoxStyle.Critical)
  
      End If
  End Sub`
  </code></pre>