Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading XML file
#4
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:
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!
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Reading XML file - by Covert2String - 04-22-2012, 04:58 PM
Re: Reading XML file - by Covert2String - 04-29-2012, 11:17 AM
Re: Reading XML file - by brandonio21_phpbb3_import2 - 04-30-2012, 03:19 PM
Re: Reading XML file - by Covert2String - 04-30-2012, 03:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with PCX file. Worf 2 14,199 10-15-2014, 10:41 AM
Last Post: Worf
  Protecting a file Covert2String 4 15,306 05-10-2012, 12:01 AM
Last Post: Covert2String
  Create a new file Covert2String 5 18,960 04-11-2012, 02:47 PM
Last Post: brandonio21
  Apply a diff file to another file Covert2String 8 27,764 04-09-2012, 03:21 PM
Last Post: Covert2String

Forum Jump:


Users browsing this thread: 1 Guest(s)