I am creating a file system and I am currently working on adding a new user. I have the basic portion set up, however, I need to test to verify the user does not already exist prior to adding the user to the file (using streamwriter) otherwise I want an error msg to show "User already exists."
...with that the code.
My questions are, A.) Where should the test be placed? I think just prior to writing to the file, but I may be wrong.
B.) What is the best way to test for an existing user?
Thank you.
...with that the code.
Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim student As StreamWriter
student = File.AppendText(InputBox("Please enter file name?" & ".txt"))
Dim newstudent As Student_info
newstudent.strFirst = txtFirst.Text
newstudent.strLast = txtLast.Text
newstudent.strAddress = txtAddress.Text
newstudent.strPhone = txtAddress.Text
newstudent.intAb = CInt(txtAb.Text)
newstudent.strMother = txtMother.Text
newstudent.blnPermission = CBool(chkPermission.Text)
student.WriteLine(newstudent.strFirst)
student.WriteLine(newstudent.strLast)
student.WriteLine(newstudent.strAddress)
student.WriteLine(newstudent.strPhone)
student.WriteLine(newstudent.intAb)
student.WriteLine(newstudent.strMother)
student.WriteLine(newstudent.blnPermission)
student.Close()
txtFirst.Clear()
txtLast.Clear()
txtAddress.Clear()
txtPhone.Clear()
txtAb.Clear()
txtMother.Clear()
chkPermission.Text = ""
End Sub
End ClassB.) What is the best way to test for an existing user?
Thank you.