Add formated string to lisbox?

Hey,

My program has a string (fdata), that is recieved through a wsock connection, when i go MsgBox fdata it looks like this:

Line 1
Line 2
Line 3
Line 4 (e.t.c)

That is how it should look, I now want to add each line of that string to a listbox so it looks like it does in the message box, but when i do list1.AddItem fdata it looks like this:

Line 1||Line 2||Line 3||Line 4

The || are bold things..

Does anyone know how i can split up fdata into like seperate strings so i can add them properly, or have another method.

The string fdata is sent from a c++ program that sends it like this:

char fdata[200] = "line 1
" e.t.c

so the
are what are casueing the bold || not recognised by the listobox.

Thanks for any help,
TNT

Comments

  • I don't know but I always do it like this:

    Listbox.AddItem "Line 1"
    Listbox.AddItem "Line 2"

    etc.
  • : Does anyone know how i can split up fdata into like seperate strings so i can add them properly, or have another method.
    :

    If you have VB6 you can use the Split():

    [code]
    Dim Splitted() as string
    Dim i as integer
    Splitted() = Split(fdata,"") 'Instead of the you shall use the character making the bold |'

    For i = lbound(Splitted()) to ubound(Splitted())
    list1.additem Splitted(i)
    Next
    [/code]

    ...otherwise you might have to use the Mid(), which someone else might care to explain to you...

    Hope it helps
    jacob_miw
  • Thanks, but i cant do it like that becasue i only have 1 whole string and i dont know whats gonna be in it as its sent through a socket.
  • Thanks alot, that works perfectly
  • : Hey,
    :
    : My program has a string (fdata), that is recieved through a wsock connection, when i go MsgBox fdata it looks like this:
    :
    : Line 1
    : Line 2
    : Line 3
    : Line 4 (e.t.c)
    :
    : That is how it should look, I now want to add each line of that string to a listbox so it looks like it does in the message box, but when i do list1.AddItem fdata it looks like this:
    :
    : Line 1||Line 2||Line 3||Line 4
    :
    : The || are bold things..
    :
    : Does anyone know how i can split up fdata into like seperate strings so i can add them properly, or have another method.
    :
    : The string fdata is sent from a c++ program that sends it like this:
    :
    : char fdata[200] = "line 1
    " e.t.c
    :
    : so the
    are what are casueing the bold || not recognised by the listobox.
    :
    : Thanks for any help,
    : TNT
    :
    :
    Try stripping off the || coming from your winsock connection using Left$ eg list1.AddItem Left$(fdata, (Len(fdata)-1))
    Suggest you test for the presence of the || at the end of your string first though.

    Dave
  • : : Hey,
    : :
    : : My program has a string (fdata), that is recieved through a wsock connection, when i go MsgBox fdata it looks like this:
    : :
    : : Line 1
    : : Line 2
    : : Line 3
    : : Line 4 (e.t.c)
    : :
    : : That is how it should look, I now want to add each line of that string to a listbox so it looks like it does in the message box, but when i do list1.AddItem fdata it looks like this:
    : :
    : : Line 1||Line 2||Line 3||Line 4
    : :
    : : The || are bold things..
    : :
    : : Does anyone know how i can split up fdata into like seperate strings so i can add them properly, or have another method.
    : :
    : : The string fdata is sent from a c++ program that sends it like this:
    : :
    : : char fdata[200] = "line 1
    " e.t.c
    : :
    : : so the
    are what are casueing the bold || not recognised by the listobox.
    : :
    : : Thanks for any help,
    : : TNT
    : :
    : :
    : Try stripping off the || coming from your winsock connection using Left$ eg list1.AddItem Left$(fdata, (Len(fdata)-1))
    : Suggest you test for the presence of the || at the end of your string first though.
    :
    : Dave
    :

    Or, shocking thought(!), use the idea already presented that poster has already indicated works perfectly.

    Anyway, you'd have to use Mid$ and InStr since the line has CrLf embedded in it and not just at the end.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories