I am reading a txt file, I have a txt file(customers. txt) that is read, with account numbers and passwords. Once the user enters a account number and password it should read the file and if there in there it will show the second form and end the loop. The probelm I am having is when I enter a acct # and password that is maybe the third entry in the file it is hitting the "else" statment and displaying my msgbox. What is the code I can put in front of the if statement to tell it to keep reading until the end of the file then display the error message? Below is what I have got so far, Thanks for you help.
Code:
Dim sr As IO.StreamReader
Dim Acctnumber, password As String
Private Sub frmBankATM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "RBD Bank Account Login"
End Sub
Sub OpenFile()
sr = IO.File.OpenText("customers.txt")
End Sub
Sub CloseFile()
sr.Close()
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If txtaccount.Text = "" Then
MsgBox("Please Enter a Account Number.", MsgBoxStyle.Information, "Account a password")
txtaccount.Focus()
Exit Sub
End If
If txtpassword.Text = "" Then
MsgBox("Please Enter a Password.", MsgBoxStyle.Information, "Password")
txtpassword.Focus()
Exit Sub
End If
OpenFile()
Do While sr.Peek <> -1
Acctnumber = sr.ReadLine
password = sr.ReadLine
If txtaccount.Text = Acctnumber And txtpassword.Text = Reverse(password) Then
frmMainboard.Show()
Exit Sub
ElseIf sr.Peek <> -1 Then
'ElseIf txtaccount.Text <> Acctnumber And txtpassword.Text <> password Then
MsgBox("Invalid Account Number and/or password combination", MsgBoxStyle.Critical, "Invalid Account number or Password")
txtpassword.Focus()
End If
Loop
CloseFile()
End Sub
Function Reverse(ByVal info As String) As String
Dim a, b As Integer
Dim temp As Integer
Dim password As String = ""
a = info.Length
For b = a - 1 To 0 Step -1
temp &= info.Substring(b, 1)
Next
Return temp
End Function
End Class
Comment