Hey i have a textbox that i want to read line by line and store in an ArrayList. I am currently trying to find the line break at the end of each line. Here is the code:

While i = 0
            h = ptext.IndexOf(vbCrLf)'here is where i try to find line break. i have tried everything from Chr(10) to vbLf
            If h < 0 Then
                h = ptext.Length
                i = 1
            End If
            a.Add(ptext.Substring(0, h))
            ln += 1
            If i = 0 Then ptext = ptext.Substring(h, ptext.Length)
            h = -7
        End While

Any suggestions?
thanks
m

Hi,

Use "Split" Function.

Dim MyArr
  Dim i As Long
  MyArr = Split(TextBox1.Text, VbCrLf)
  For i = 0  To UBound(MyArr)
      Debug.Print MyArr(i)
  Next

Regards
Veena

Hi,

Use "Split" Function.

Dim MyArr
  Dim i As Long
  MyArr = Split(TextBox1.Text, VbCrLf)
  For i = 0  To UBound(MyArr)
      Debug.Print MyArr(i)
  Next

Regards
Veena

A better way is as follows

If InStr(ptext,chr(10))> 0 Then
MsgBox " ptext contains chr10"
endif

regards
AV Manoharan

Hi Manoharan,

What if there are "Multiple Line Breaks" in textbox....?
Put in a loop..? Why do the excersise when it can be done in single statement.

Regards
Veena

Hi,

Use "Split" Function.

Dim MyArr
  Dim i As Long
  MyArr = Split(TextBox1.Text, VbCrLf)
  For i = 0  To UBound(MyArr)
      Debug.Print MyArr(i)
  Next

Regards
Veena

wow thanks, worked great!

The only problem is the MyArr declaration don't declare it like that (variant)

The only problem is the MyArr declaration don't declare it like that (variant)

yea instead of having debug print it, i added each one to an arraylist

Hi Manoharan,

What if there are "Multiple Line Breaks" in textbox....?
Put in a loop..? Why do the excersise when it can be done in single statement.

Regards
Veena

Veena, I think he is not using the textbox as a pipe or stream, so that they can contain any nubmebr of Carriage Returnes and Line Feeds. In a line of Text there can never be two such things.

Eventhough your programming code takes some overheads, it worked for him.

Thanks

AV Manoharan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.