Convert 10 lines To Row using vb?

sandrine10

Power Member
Joined
Apr 14, 2010
Messages
779
Reaction score
88
Hi,

I want convert the richtextbox content from 10 lines to 1 row and move to next 10 lines(1row too) and so on example:

user1
user2
user3
.
.
.
.

usern

need to write each 10 lines on 1 row like this:


Row1:user1 user2 user3 . . . . . user10
Row2:user11 user12 user13 . . . user20
.
.
etc

Any idea?
 
Last edited:
Try this

Dim cnt as Integer
cnt = 0;
dim result as String
result=""
Do Until cnt = RichTextBox1.Lines.Count - 1


result = result & RichTextBox1.Lines(cnt)


cnt = cnt +1


Loop
 
Try this

Dim cnt as Integer
cnt = 0;
dim result as String
result=""
Do Until cnt = RichTextBox1.Lines.Count - 1


result = result & RichTextBox1.Lines(cnt)


cnt = cnt +1


Loop

Fine,just how to get the10 lines per row each time?
 
Anyone could help to solve this today?
 
For Each line As String In RichTextBox1.Lines
Dim newString As String = line.Replace(vbCr, "").Replace(vbLf, "")
RichTextBox2.AppendText(newString)
Next


Just tested and work fine
 
Just tested and work fine
It works fine(as helpinghand code works fine too)!just need to get 10 lines in 1 row and "VbCrLf" next 10 lines .. and so on Do you know how?
 
Bump
need to get 10 lines in 1 row and "VbCrLf" next 10 lines .. and so on
It works fine(as helpinghand code works fine too)!just need to get 10 lines in 1 row and "VbCrLf" next 10 lines .. and so on Do you know how?
 
Try this


Dim cnt as Integer
cnt = 0;
dim result as String
dim array() as String
dim i as integer
result=""
i=0
Do Until cnt = RichTextBox1.Lines.Count - 1
result = result & RichTextBox1.Lines(cnt)
cnt = cnt +1


if cnt mod 10 =0 then
array(i)=result
i = i+1
result=""
End if
Loop


for j = 0 to i
msgbox(array(i))
Next
 
NullReferenceException Was Unhandled!
variable 'array' is used before it has been assigned a value.
Try this


Dim cnt as Integer
cnt = 0;
dim result as String
dim array() as String
dim i as integer
result=""
i=0
Do Until cnt = RichTextBox1.Lines.Count - 1
result = result & RichTextBox1.Lines(cnt)
cnt = cnt +1


if cnt mod 10 =0 then
array(i)=result
i = i+1
result=""
End if
Loop


for j = 0 to i
msgbox(array(i))
Next
 
Try this function:

Code:
    Private Function rowList(ByVal usNames() As String)

        Dim counter As Integer = 0
        Dim usString As String = ""

        For i = 0 To usNames.Count - 1

            If usNames(i) <> Nothing Then
                If counter = 9 Then
                    usString = usString & usNames(i) & Environment.NewLine
                    counter = 0
                Else
                    usString = usString & " " & usNames(i)
                    counter += 1
                End If
            End If
        Next

        Return usString

    End Function

Remember, when you use this function, you have to pass richtextbox.lines, not text.
 
Send me your email i will send complete project i made for this in vs 2010
 
What is the problem? Just add 10 linebreaks at the end of each loop

for(i=0; i<10; i++)
{
Environment.NewLine;
}
 
Nice works as well.
Try this function:

Code:
    Private Function rowList(ByVal usNames() As String)

        Dim counter As Integer = 0
        Dim usString As String = ""

        For i = 0 To usNames.Count - 1

            If usNames(i) <> Nothing Then
                If counter = 9 Then
                    usString = usString & usNames(i) & Environment.NewLine
                    counter = 0
                Else
                    usString = usString & " " & usNames(i)
                    counter += 1
                End If
            End If
        Next

        Return usString

    End Function

Remember, when you use this function, you have to pass richtextbox.lines, not text.
 
Despite the several options posted by other users, I thought I would take a crack at this.

Nothing special, just putting out there another way to do it.

Code:
[FONT=arial]​[/FONT][FONT=tahoma]Private Function LinesToRow(Lines As String()) As String        
        Dim StrBuilder As New System.Text.StringBuilder
        Dim Count As Integer


        Do While Count < Lines.Count
            StrBuilder.Append(String.Join(" ", Lines.Skip(Count).Take(10)) & Environment.NewLine)
            Count += 10
        Loop


        Return StrBuilder.ToString.TrimEnd(Environment.NewLine.ToCharArray)
End Function[/FONT]

You would have to feed it your RichTextBox.Lines() like so:

Code:
[FONT=tahoma]MessageBox.Show(LinesToRow(RichTextBox1.Lines), "10 Lines At A Time")[/FONT]
 
looks like this was already solved for you, if you still need help just let me know
 
Split & Mid. No other programming languages offer these functions, that is why I code VB.
 
Back
Top