views:

336

answers:

1

Hi, this is probably not that hard to do. But I've got two text files. The first has got a list of certain keywords. Each one if these keywords are fed into a combobox.

Now, when I choose one of the items from this combobox, I want to search the other textfile for the same keyword and read from that point to the next keyword. And then feed each line into a listbox. Hope I make myself understood.

Perhaps I should use an INI-file for this purpose, doesn't really matter for me.

The textfiles have this structure; Textfile1:

London
Oslo
New York
Hamburg
Amsterdam

The second textfile has this structure; Textfile2:

'London'
Apples
Oranges
Pears

'Oslo'
Pasta
Salami
Monkeyballs

'New York'
Dada
Duda
Dadadish

Etc etc.

Is this possible? The reason I want to do it this way is to create a fully dynamic system. One which relies fully on whatever information is stored in these textfiles. I'm gonna build pretty complex strings from these results later on.

So far, I've got this to read the first file and add each line to the combobox:

Dim oReadMenuFunction as System.IO.StreamReader
oReadMenuFunction = IO.File.OpenText("textfile1.txt")

Do While oReadMenuFunction.Peek <> -1
    Dim LineIn as String = oReadMenuFunction.ReadLine()
    Combobox.Items.Add(LineIn)
Loop
+1  A: 

Here's a sample function you could use to parse your second file. It takes a keyword as argument and returns the associated items:

Function ReadData(ByRef keyword As String) As IEnumerable(Of String)
    Dim result = New List(Of String)
    Using reader = New StreamReader("file2.txt")
        Dim line As String = reader.ReadLine()
        Dim take = False
        Do While line IsNot Nothing
            If line.StartsWith("'") Then
                take = False
            End If
            If String.Equals("'" + keyword + "'", line) Then
                take = True
            End If
            If take And Not String.IsNullOrEmpty(line) And Not line.StartsWith("'") Then
                result.Add(line)
            End If
            line = reader.ReadLine()
        Loop
    End Using
    Return result
End Function

And you use it like this:

Dim items = ReadData("London")
Darin Dimitrov
Thanx! I had to redo some of it but the main structure worked like a charm! :)
Kenny Bones