I have some data that is in a txt file. When the application loads, I will have the ability to add more data to the file. Though there is one field that can't be duplicated. So I need to check the existing records against the data I am going to enter.
When I'm in the application I have the lost_focus command on the field I want to check and I store the data into an array. So if I enter a duplicate employee number there will be an error.
The problem is when I open the application it won't check against existing data, just what I enter in now. Any ideas on how I can make this work? I know It's simple I just can't place it.
Lost Focus Code
Private Sub txtEmployeeNumber_LostFocus(sender As Object, e As EventArgs) Handles txtEmployeeNumber.LostFocus
'Check For Existing Employee Number
Dim index As Integer = Array.IndexOf(empArray, CInt(txtEmployeeNumber.Text))
If index = -1 Then
ReDim Preserve empArray(empArray.Length)
empArray(empArray.Length - 1) = CInt(txtEmployeeNumber.Text)
'Show Error If Dupicate
MessageBox.Show("Employee Id Already Entered" & vbCrLf & _
"Please Enter A Unique Employee Number")
txtEmployeeNumber.Text = ""
Here is my code that writes to the file
Dim strFirstName As String = txtFirstName.Text
Dim strMiddleName As String = txtMiddleName.Text
Dim strLastName As String = txtLastName.Text
Dim intEmployeeNumber As Integer = CInt(txtEmployeeNumber.Text)
Dim strDepartment As String = ComboBoxDepartment.SelectedItem.ToString()
Dim strTelephone As String = txtPhoneNumber.Text
Dim intExtension As Integer = CInt(txtExtension.Text)
Dim strEmail As String = txtEmailAddress.Text
Dim intBaseSalary As Integer = CInt(txtBaseSalary.Text)
employeeFile = File.AppendText(strFileName)
'Display Message Box When Data Is Entered, Then Clear For New Data
MessageBox.Show("Data Entered Successfully")
'Display Error If There Is A Problem With File (For Extra Measures)
MessageBox.Show("File Can't Be Written To")