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?

Recommended Answers

All 6 Replies

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

stats79,, are u using or vb6?
streamreader is a function in not in vb6..

VB Express

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
commented: Nicely executed. +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.