i have changed an old vb6 application to 2005.net and i want to know if this sub (which does work) could be better, by that i mean have i used the right functions ?, are there better(faster) ones ?
this removes a username and every line under it until it reaches another username.
VB Code:
Public Sub RemoveUser(ByVal StringUser As String) Dim sr As New IO.StreamReader("C:\usernamesinfo.txt") Dim sw As New IO.StreamWriter("C:\usernamesinfo2.txt", True) Dim Found As Boolean, Lines As String Do While sr.Peek >= 0 Lines = sr.ReadLine If Found = False Then If InStr(Lines, "USERNAME" & StringUser) = 0 Then sw.WriteLine(Lines) Else Found = True End If Else If InStr(Lines, "USERNAME") > 0 Then Found = False sw.WriteLine(Lines) End If End If Loop sr.Close() sw.Close() IO.File.Delete("C:\usernamesinfo.txt") IO.File.Move("C:\usernamesinfo2.txt", "C:\usernamesinfo.txt") End Sub
thanks.




Reply With Quote