I'm trying to save a class to a text file and I'm getting mixed results. Half the time the last line of the add is in the file and sometimes not. I've not been able to get a consistent output to the file.
So, I added a debug to show me what was being written just prior to the StreamWriter.Write
and it showed the line that I added but it doesn't show up in the file.
^ This line is the last line that isn't being written to the file.
Here's what my code where I save the data looks like:
Private sub SaveMemoUsersFile()
If _memoList is Nothing Then
return
End If
Dim memofile = Path.Combine(Configuration.DataFileLocations, $"{Configuration.CompanyID}ucMemoUsers.txt")
Const quote As String = """"
Const comma As String = ","
Dim both = $"{quote}{comma}{quote}"
Using sw = New StreamWriter(memofile)
For Each memoUsers As MemoUsers In _memoList
Dim sb = New StringBuilder()
sb.Append(quote)
sb.Append(memoUsers.Initials)
sb.Append(both)
sb.Append(memoUsers.EmailAddress)
sb.Append(both)
sb.Append(memoUsers.DelinquentLetterCode)
sb.Append(both)
sb.Append(memoUsers.Description)
sb.Append(quote)
'sb.Append(vbCr)
console.write(sb) <--- shows the last line
sw.WriteLine(sb.ToString()) <--- but doesn't write it to the file
Next
End Using
_memoList = nothing
End sub
Anyone have any suggestions? I'm completely lost as to why this is writing to the file randomly.