04-30-2012, 03:19 PM
So here is my method of parsing the text file. The form contains two listboxes (1 and 2), 1 contains the categories while 2 contains the actual values.
Here is the code I used:
You may find it easier to view the code on PasteBin:
<!-- m --><a class="postlink" href="http://pastebin.com/M7R1FZaK">http://pastebin.com/M7R1FZaK</a><!-- m -->
Hopefully this helps!
Here is the code I used:
Code:
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim reader As New System.IO.StreamReader("C:\Users\Brandon\Desktop\lol.txt") 'Read the text file
Dim i As Integer = 0 'Keep track if the item is a category or a value
For Each entry In reader.ReadToEnd.Split(Chr(34)) 'Split by quotation marks
'Here we check to see if the value or category contains invalid symbols that are
'not necessarily pertinent to the information that we need to gather.
'If the string contains these symbols, they are removed.
If (entry.Contains("<") Or entry.Contains(">") Or entry.Contains(" ") Or entry.Contains("/") Or entry.Contains("\")) Then
Try
entry = entry.Replace("<", "")
entry = entry.Replace(">", "")
entry = entry.Replace(" ", "")
entry = entry.Replace("/", "")
entry = entry.Replace("\", "")
Catch ex As Exception
Continue For
End Try
End If
If (i Mod 2 = 0) Then 'The item is a category
ListBox1.Items.Add(entry)
Else 'The item is a value
ListBox2.Items.Add(entry)
End If
i += 1 'Increase the counter of the category determiner so we can keep track
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox2.SelectedIndex = ListBox1.SelectedIndex
End Sub
End Class
You may find it easier to view the code on PasteBin:
<!-- m --><a class="postlink" href="http://pastebin.com/M7R1FZaK">http://pastebin.com/M7R1FZaK</a><!-- m -->
Hopefully this helps!