Create a text file called TOONS.TXT with the following data:
Daffy Duck
Daffy Duck
Daisy Duck
Fred Flintstone
Mighty Mouse
Minnie Mouse
Porky Pig
Yosemite Sam

Write a program to find and display those names in the TOONS.TXT file that are repeated. Assume that the file has already been sorted into alphabetical order. When a name is found to be repeated, display it only once.

Having trouble writing this program, can anyone help?

5 Years
Discussion Span
Last Post by codeorder

text file is created just need assistance with the program.


@Stats, you will definitely have to show some more effort. What code do you have so far? The question looks like it has been copied directly from a homework task. We WILL help, if you show some effort.


Sorry, new to the fourm
This is what I have:

Dim name As String = " "
    Dim sr As IO.StreamReader = IO.File.OpenText("toons.txt")
    Do While (name <> txtName.Text) And (sr.Peek <> -1)
      name = sr.ReadLine
    If (name = txtName.Text) Then
      txtNotify.Text = "Name located: " & " " & name
      txtNotify.Text = "Sorry - the name not located."
    End If
  End Sub

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.


See if this helps.
2 TextBoxes(MultiLine = True)

Public Class Form1
    Private myCoolToonsFile As String = "C:\toons.txt" '// your File.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists(myCoolToonsFile) Then '// check if file exists.
            Dim arTemp() As String = IO.File.ReadAllLines(myCoolToonsFile) '// Load File in a String Array, which loads each line as a individual array.
            For Each fileLine As String In arTemp '// loop thru all arrays.
                With TextBox1 '// loads all file lines.
                    If Not .Text = "" Then .Text &= vbNewLine & fileLine Else .Text = fileLine '// add line.
                End With
                With TextBox2 '// loads only file lines that do not repeat.
                    If Not .Text.Contains(fileLine) Then '// check if TextBox does Not Contain the file line.
                        If Not .Text = "" Then .Text &= vbNewLine & fileLine Else .Text = fileLine '// add line.
                    End If
                End With
        End If
    End Sub
End Class
Nicely executed.
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.