CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2004
    Posts
    14

    opening a text file in a list box

    I've been trying to open a text file that i have created in windows notepad, to open up into a list box that i have created in a windows form. But im confused with the coding. If someone could possibly explain this to me in simple terms it would be great. Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: opening a text file in a list box

    bboy_romeo,
    Code:
    Dim file As IO.StreamReader
    Dim MyStr as String
    Dim filename As String ="YourFileNameHere.txt"
    
    file = New IO.StreamReader(filename, System.Text.Encoding.Default)
    MyStr = file.Readline()
    While Not MyStr Is Nothing
        ListBox1.Items.Add(MyStr)
        MyStr = file.Readline()
    End While
    file.Close()
    Hope it helps
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured