Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fo As New OpenFileDialog fo.RestoreDirectory = True fo.Multiselect = False fo.Filter = "txt files (*.txt)|*.txt" fo.FilterIndex = 1 fo.ShowDialog() If (Not fo.FileName = Nothing) Then End If End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fo As New OpenFileDialog fo.RestoreDirectory = True fo.Multiselect = False fo.Filter = "txt files (*.txt)|*.txt" fo.FilterIndex = 1 fo.ShowDialog() If (Not fo.FileName = Nothing) Then Dim lines As New List(Of String) Using sr As New System.IO.StreamReader(fo.FileName) While sr.Peek <> -1 Dim line As String = sr.ReadLine() Dim isNew As Boolean = True For Each found As String In lines If (found = line) Then isNew = False Next If (isNew) Then lines.Add(sr.ReadLine()) End While End Using End If End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fo As New OpenFileDialog fo.RestoreDirectory = True fo.Multiselect = False fo.Filter = "txt files (*.txt)|*.txt" fo.FilterIndex = 1 fo.ShowDialog() If (Not fo.FileName = Nothing) Then Dim lines As New List(Of String) Using sr As New System.IO.StreamReader(fo.FileName) While sr.Peek <> -1 Dim line As String = sr.ReadLine() Dim isNew As Boolean = True For Each found As String In lines If (found = line) Then isNew = False Next If (isNew) Then lines.Add(sr.ReadLine()) End While End Using Dim savePath As String If (CheckBox1.Checked) Then If (My.Computer.FileSystem.FileExists(fo.FileName)) Then My.Computer.FileSystem.DeleteFile(fo.FileName) End If savePath = fo.FileName Else Dim fs As New SaveFileDialog fs.RestoreDirectory = True fs.Filter = "txt files (*.txt)|*.txt" fs.FilterIndex = 1 fs.ShowDialog() If (fs.FileName = Nothing) Then savePath = fo.FileName Else savePath = fs.FileName End If End If Using sw As New System.IO.StreamWriter(savePath) For Each line As String In lines sw.WriteLine(line) Next End Using End If End Sub
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim fo As New OpenFileDialog fo.RestoreDirectory = True fo.Multiselect = False fo.Filter = "txt files (*.txt)|*.txt" fo.FilterIndex = 1 fo.ShowDialog() If (Not fo.FileName = Nothing) Then Dim lines As New List(Of String) Using sr As New System.IO.StreamReader(fo.FileName) While sr.Peek <> -1 Dim line As String = sr.ReadLine() Dim isNew As Boolean = True For Each found As String In lines If (found = line) Then isNew = False Next If (isNew) Then lines.Add(sr.ReadLine()) End While End Using Dim savePath As String If (CheckBox1.Checked) Then If (My.Computer.FileSystem.FileExists(fo.FileName)) Then My.Computer.FileSystem.DeleteFile(fo.FileName) End If savePath = fo.FileName Else Dim fs As New SaveFileDialog fs.RestoreDirectory = True fs.Filter = "txt files (*.txt)|*.txt" fs.FilterIndex = 1 fs.ShowDialog() If (fs.FileName = Nothing) Then savePath = fo.FileName Else savePath = fs.FileName End If End If Using sw As New System.IO.StreamWriter(savePath) For Each line As String In lines sw.WriteLine(line) Next End Using End If End Sub End Class