I've seen this question on here a few times but I can't seem to find the right answer. I currently have a Windows Form Application I'm writing in VB that creates player profiles (this is a school project). On the 'Registration' page I take in the information and read it to a .txt file with each field comma deliminator line by line. This makes for a .txt that looks something like this:
Dan,Boyle,M,39,(707) 555-1234,555 S. West Street,18,D,R
Justin,Braun,M,27,(916) 555-1255,858 W. South St,5,D,L
I ran right new lines to this, and call this just fine but what I need to do for my project is be able to edit a player profile. What I've found so far is that the best way would be to re-write the whole line, which I've managed to do. But what I can't figure out is how to remove the current line and replace.
Dim FileString As String = "MasterRoster.txt"
Dim index As Integer = Home.cbPlayerLookUp.SelectedIndex
Dim playerInfo() As String = File.ReadAllLines(FileString)
Dim FieldString() As String
Dim RecordString As String = ""
If Not playerInfo.Length < index Then
FieldString = playerInfo(index).Split(","c)
'Update Player stats)
If CInt(FieldString(16)) = index Then
FieldString(12) = CStr(CInt(FieldString(12)) + CInt(txtGoals.Text))
FieldString(13) = CStr(CInt(FieldString(13)) + CInt(txtAssists.Text))
FieldString(14) = CStr(CInt(FieldString(14)) + CInt(txtPIM.Text))
FieldString(15) = CStr(CInt(FieldString(15)) + CInt(txtGames.Text))
'(FirstName0, LastName1, Gender2, Age3, Phone4, Address5, Experience6, Position7, Handedness8, Team9, Jersey#10, imgPath11, Goals12, Assists13, PIM14, Total Games15, playerID Number16)
RecordString = FieldString(0) & "," & FieldString(1) & "," & FieldString(2) & "," & FieldString(3) & "," & FieldString(4) & "," & FieldString(5) &
"," & FieldString(6) & "," & FieldString(7) & "," & FieldString(8) & "," & FieldString(9) & "," & FieldString(10) & "," & FieldString(11) & "," & FieldString(12) & "," &
FieldString(13) & "," & FieldString(14) & "," & FieldString(15) & "," & FieldString(16) & vbNewLine
End If
My.Computer.FileSystem.WriteAllText(FileString, RecordString, True)
End If
This will currently add a new line to the bottom of my .txt file "MasterRoster.txt" with the updated information at the end, but the old one is still there. How can I instead replace the old line?