Thread: How to...

Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    nay's Avatar
    Join Date
    Dec 2010
    Gender
    male
    Posts
    15
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by XiAtomikiX View Post
    well i think with what i see your better off using xml to store the contents of the listbox (easier to grab in my book)
    then you can use streamreader and streamwriter to write and read the text file

    with the source below create a file named "list.xml"
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <main> 
    </main>
    put that in it and save then
    you can use the source below and it will make the whole thing work
    Code:
    Imports System****
    
    Public Class Form1
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim xdoc As New Xml.XmlDocument
            xdoc.Load("list.xml")
            Dim titleNode As Xml.XmlNode = xdoc.Item("main")
            Dim NewElement As Xml.XmlElement
            NewElement = xdoc.CreateElement("title") ' creates new element <title>valuehere</title>
            NewElement.InnerText = TextBox1.Text
            titleNode.AppendChild(NewElement)
            xdoc.Save("list.xml") ' Saves the xml file with the content added
            ListBox1.Items.Clear()
            UpdateList()
            Dim path As String = TextBox1.Text + ".txt"
            Dim writer As New StreamWriter(path)
            Dim text As String = RichTextBox1.Text
            writer.Write(text)
            writer.Close()
        End Sub
        Public Sub UpdateList()
            ListBox1.Items.Clear()
            Dim xdoc As New Xml.XmlDocument
            xdoc.Load("list.xml")
            Dim titleNode As Xml.XmlNode = xdoc.Item("main")
            Dim element As Xml.XmlElement
    
    
            For Each element In titleNode
                ListBox1.Items.Add(element.InnerText)
            Next
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Items.Clear()
            UpdateList()
    
        End Sub
    
        Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
            Dim loadpath As String = ListBox1.SelectedItem + ".txt"
            Dim reader As New StreamReader(loadpath)
            Do While reader.Peek() >= 0
                RichTextBox1.Text = reader.ReadToEnd()
            Loop
            reader.Close()
        End Sub
    
    End Class
    the way it works is save the textbox.text as the title of the .txt file you save then when you dblclick the item in listbox it opens the txt file inside of a richtextbox

    i think this is what u were trying to accomplish.
    cheers pal.

  2. #17
    ariffin1201's Avatar
    Join Date
    Jul 2011
    Gender
    male
    Location
    White House
    Posts
    605
    Reputation
    10
    Thanks
    31
    Cheers for the long sentence

  3. #18
    nay's Avatar
    Join Date
    Dec 2010
    Gender
    male
    Posts
    15
    Reputation
    10
    Thanks
    0
    Quote Originally Posted by XiAtomikiX View Post
    well i think with what i see your better off using xml to store the contents of the listbox (easier to grab in my book)
    then you can use streamreader and streamwriter to write and read the text file

    with the source below create a file named "list.xml"
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <main> 
    </main>
    put that in it and save then
    you can use the source below and it will make the whole thing work
    Code:
    Imports System****
    
    Public Class Form1
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim xdoc As New Xml.XmlDocument
            xdoc.Load("list.xml")
            Dim titleNode As Xml.XmlNode = xdoc.Item("main")
            Dim NewElement As Xml.XmlElement
            NewElement = xdoc.CreateElement("title") ' creates new element <title>valuehere</title>
            NewElement.InnerText = TextBox1.Text
            titleNode.AppendChild(NewElement)
            xdoc.Save("list.xml") ' Saves the xml file with the content added
            ListBox1.Items.Clear()
            UpdateList()
            Dim path As String = TextBox1.Text + ".txt"
            Dim writer As New StreamWriter(path)
            Dim text As String = RichTextBox1.Text
            writer.Write(text)
            writer.Close()
        End Sub
        Public Sub UpdateList()
            ListBox1.Items.Clear()
            Dim xdoc As New Xml.XmlDocument
            xdoc.Load("list.xml")
            Dim titleNode As Xml.XmlNode = xdoc.Item("main")
            Dim element As Xml.XmlElement
    
    
            For Each element In titleNode
                ListBox1.Items.Add(element.InnerText)
            Next
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ListBox1.Items.Clear()
            UpdateList()
    
        End Sub
    
        Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
            Dim loadpath As String = ListBox1.SelectedItem + ".txt"
            Dim reader As New StreamReader(loadpath)
            Do While reader.Peek() >= 0
                RichTextBox1.Text = reader.ReadToEnd()
            Loop
            reader.Close()
        End Sub
    
    End Class
    the way it works is save the textbox.text as the title of the .txt file you save then when you dblclick the item in listbox it opens the txt file inside of a richtextbox

    i think this is what u were trying to accomplish.
    also will i need to call the xml on form load?

  4. #19
    XiAtomikiX's Avatar
    Join Date
    Sep 2012
    Gender
    male
    Posts
    141
    Reputation
    22
    Thanks
    31
    Quote Originally Posted by nay View Post
    also will i need to call the xml on form load?
    Code:
    ListBox1.Items.Clear()
            UpdateList() ' this thread contains the code to load xml into listbox
    then the update list is called
    Code:
        Public Sub UpdateList()
            ListBox1.Items.Clear()
            Dim xdoc As New Xml.XmlDocument
            xdoc.Load("list.xml")
            Dim titleNode As Xml.XmlNode = xdoc.Item("main")
            Dim element As Xml.XmlElement
    
    
            For Each element In titleNode
                ListBox1.Items.Add(element.InnerText)
            Next
        End Sub
    all of this was in the source code i just posted.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. how about Tantra Online Game
    By scoutranger in forum General Gaming
    Replies: 2
    Last Post: 09-25-2018, 06:57 AM
  2. How many people on this forum Play WoW?
    By RebornAce in forum General
    Replies: 27
    Last Post: 12-31-2009, 05:27 PM
  3. How to Use Tsearch
    By wardo1926 in forum Hack Requests
    Replies: 5
    Last Post: 12-18-2007, 09:24 PM
  4. How to get Perl
    By shercipher in forum Programming
    Replies: 2
    Last Post: 01-02-2006, 11:28 PM
  5. How To Brute Force
    By Flawless in forum Game Hacking Tutorials
    Replies: 0
    Last Post: 01-01-2006, 05:01 PM