Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET ListBox line
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 16-Nov-12 6:52am
Edited 16-Nov-12 6:57am
v2
Comments
ProgramFOX at 16-Nov-12 12:55pm
   
What's the value of vbNewLine?
Member 9605439 at 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 at 16-Nov-12 13:01pm
   
No! If this things executes at all, it has a value. And it should.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

"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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I used this code for my minecraft server creator but here it is:
 
ListBox1.Items.Clear()
For X As Integer = 0 To TextBox3.Lines.Count - 1
ListBox1.Items.Add(TextBox3.Lines(X))
Next
 
Hope this helped Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 370
1 Sergey Alexandrovich Kryukov 195
2 Prakriti Goyal 177
3 jlopez788 134
4 _Amy 110
0 OriginalGriff 6,762
1 Sergey Alexandrovich Kryukov 5,539
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 17 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100