Re: messed up listbox entries

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



First, remove the vbCRLF. I am not sure what the problem is, but the line
feed will definately not help.

You are adding a string to a collection, and the line feed is ending up as
part of the string, not as a delimiter.

To be honest, the sytax of your items.add looks fine to me. It is the same
code I use to populate my listbox.

I would make one change, however. Strictly for code readability and
debugging, create a variable to hold your string and pass it to the listbox
items.add. Also write this value out to the console to make sure the
problem is not with the string itself.

dim strListBoxItem as string
strListBoxItem = line.Substring(0, (line.IndexOf(",")))
console.writeline("List box item = " & strListBoxItem)
lstNames.Items.Add(strListBoxItem )

"Patrick Sullivan" <psully@xxxxxxxxx> wrote in message
news:3vydnQ8h8cWT6PbenZ2dnUVZ_tmdnZ2d@xxxxxxxxxxxx
> I am trying to read a text file laid out like, "textfield1, textfield2,
> etc," and only extract the first value (textfield1) to add to the listbox.
> But instead of listing vertically, I get three rows across of textfield1,
> which is the correct data, but not the correct format. I put a crlf in the
> lines, but that did not help at all. TIA
>
> Private Sub LoadListbox()
>
> Try
>
> Dim sr As StreamReader = New StreamReader("Names.txt")
>
> Dim line As String
>
> line = sr.ReadLine()
>
> Do Until sr.Peek = -1
>
> line = sr.ReadLine()
>
> 'MsgBox("Line is " & line.Length & " long")
>
> lstNames.Items.Add(line.Substring(0, (line.IndexOf(","))) & vbCrLf)
>
> Loop
>
> sr.Close()
>
> Catch E As Exception
>
> MsgBox("The file could not be read")
>
> MsgBox(E.Message)
>
> End Try
>
> End Sub
>
> --
>
> Patrick Sullivan
>
>


.



Relevant Pages

  • Re: messed up listbox entries
    ... Patrick Sullivan, AA-BA, BA-IT ... > part of the string, ... > code I use to populate my listbox. ... >> Private Sub LoadListbox() ...
    (microsoft.public.dotnet.languages.vb)
  • Re: messed up listbox entries
    ... good idea about the console output testing. ... > part of the string, ... > code I use to populate my listbox. ... >> Private Sub LoadListbox() ...
    (microsoft.public.dotnet.languages.vb)
  • Listbox And Combobox Control Buffer Overflow
    ... = Listbox And Combobox Control Buffer Overflow ... As past history has shown us, Windows has many buffer overflow resulting ... Pointer to the null-terminated string that ... After sending a message with a large pathname utilman will cause an ...
    (Bugtraq)
  • [Full-Disclosure] Listbox And Combobox Control Buffer Overflow
    ... = Listbox And Combobox Control Buffer Overflow ... As past history has shown us, Windows has many buffer overflow resulting ... Pointer to the null-terminated string that ... After sending a message with a large pathname utilman will cause an ...
    (Full-Disclosure)
  • Re: Listbox to delimited text file
    ... suggestion. ... Listbox, although that would be okay, I just want the user to fill up maybe ... Public Function PutFile(sFn As String, ... Open sFn For Binary Access Write Lock Read Write As fh ...
    (microsoft.public.vb.controls)