list boxs

I've recieved a string from a server which is like

"string blah blah" & vbCrLf & "some more blah blah"

when I put into the list box it stops adding data at Chr(13)  how do i do this ?
and after each Chr(13) i want it to goto next line
Dark_AngelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
Here's a short simple code snippet you can use, just set sValue equal to the string and add a vbCrLf sign to the end of the string, this makes the code easier to read/code.

  Dim sValue As String
  Dim OldNrTecken As Long
  Dim NrTecken As Long

  sValue = "string blah blah" & vbCrLf & "some more blah blah" & vbCrLf
 
  OldNrTecken = 1
  NrTecken = InStr(NrTecken + 1, sValue, vbCrLf)
  Do Until (NrTecken = 0)
    If (NrTecken - OldNrTecken > 0) Then
      List1.AddItem Mid$(sValue, OldNrTecken, NrTecken - OldNrTecken)
    End If
    OldNrTecken = NrTecken + Len(vbCrLf)
    NrTecken = InStr(OldNrTecken, sValue, vbCrLf)
  Loop
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
Here is another way of doing it:

Private Sub Command1_Click()
Dim arrElements As Variant
Dim sValue As String
Dim varElement As Variant

    sValue = "string blah blah" & vbCrLf & "some more blah blah" & vbCrLf
    arrElements = Split(sValue, vbCrLf)
   
    For Each varElement In arrElements
        If Len(Trim$(varElement)) > 0 Then
            List1.AddItem varElement
        End If
    Next
End Sub
0
VbmasterCommented:
The big difference is that the Split function is a VB6-only function, if you have VB6 maybe emoreau's solution looks like the best, if you have VB5 then you will have to use something like my code.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dark_AngelAuthor Commented:
thanks.. the code you guys sent me worked brilliant.  thanks for all.
0
Dark_AngelAuthor Commented:
Hey, I used the code from emoreau because I have VB6.  now it's getting the whole string and putting it all in one line,  I need to to add to the next line when VbCrLf is recieved.  Any idea's ?
0
Éric MoreauSenior .Net ConsultantCommented:
What do you mean? you have only one line in your listbox? If so and you had copied the code well this must be because you don't have the vbCrLF character in your string!
0
VbmasterCommented:
Some OS's uses vbLf as new line-character, vbCrLf means Chr$(13) + Chr$(10) and vbCr means only Chr(10). You can check what value you get with code like this..

Debug.Print Instr(thestring, vbCrLf)
Debug.Print Instr(thestring, vbCr)
Debug.Print Instr(thestring, vbLf)

...to see what kind of new line-character the server you get the string from uses (the one that doesn't return 0 (zero).
0
Dark_AngelAuthor Commented:
I pretty much know what it's sending,
but I think when i request for this data it's just Chr(10) instead of carriage return.  I'll try it out, thanks alot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.