Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, all i want to do is open the text in the listbox on separate lines so i can individually click them when the program is running:
Current code:


Private Sub getlist_Click(sender As Object, e As EventArgs) Handles getlist.Click
        Dim aclient As New Net.WebClient

        aclient.Credentials = New Net.NetworkCredential("****", "****")
        Dim a As String
        a = aclient.DownloadString("ftp://URL.chat.txt")

        Dim b As String() = a.Split(vbNewLine)
        ListBox1.Items.AddRange(b)

It currently opens it all on one line... can anyone help?
Example:
In text file

192939394:2993
293992394:9324
293949394:4992

Currently displays:
192939394:2993293992394:9324293949394:4992

I want it to display like in the text file, but be interactive by being in the listbox
Posted
Updated 16-Nov-12 6:57am
v2
Comments
Thomas Daniels 16-Nov-12 12:55pm    
What's the value of vbNewLine?
Member 9605439 16-Nov-12 12:58pm    
it doesnt have a value, its just something i added in to see if it helped

It was one of the suggestions
Sergey Alexandrovich Kryukov 16-Nov-12 13:01pm    
No! If this things executes at all, it has a value. And it should.
--SA

Try this:
VB
Private Sub getlist_Click(sender As Object, e As EventArgs) Handles getlist.Click
Dim aclient As New Net.WebClient
aclient.Credentials = New Net.NetworkCredential("****", "****")
Dim a As String
a = aclient.DownloadString("ftp://URL.chat.txt")

Dim b As String() = a.Split(vbLf)
ListBox1.Items.AddRange(b)


Hope this helps.
 
Share this answer
 
"Does not have a value" is absurd — please see my comment to the question.

One little problem is that you don't know what is the line delimiter in "URL.char.txt" — it is system dependent, and original OS also could be unknown, but it's relatively simple to write "one-size-fits-all" code, something like a.Split(New Char() {ControlChars.Lf, ControlChars.Tab}, System.StringSplitOptions.RemoveEmptyEntries).

There are other delimiter as Unicode section/paragraph end characters, but they are very rare these days; if you want, you can also take them into account. You might need to auto-detect encoding with BOM, if the text might use Unicode.

—SA
 
Share this answer
 
I used this code for my minecraft server creator but here it is:

VB
ListBox1.Items.Clear()
For X As Integer = 0 To TextBox3.Lines.Count - 1
ListBox1.Items.Add(TextBox3.Lines(X))
Next


Hope this helped :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900