1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Convert 10 lines To Row using vb?

Discussion in 'Visual Basic .NET' started by sandrine10, Mar 3, 2014.

  1. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    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: Mar 3, 2014
  2. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,364
    Likes Received:
    5,425
    Gender:
    Male
    Location:
    South Africa
    Home Page:
  3. helpinghand

    helpinghand BANNED BANNED

    Joined:
    Jul 15, 2013
    Messages:
    194
    Likes Received:
    13
    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
     
    • Thanks Thanks x 1
  4. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Fine,just how to get the10 lines per row each time?
     
  5. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
  6. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Anyone could help to solve this today?
     
  7. hajrobaba

    hajrobaba Regular Member

    Joined:
    Jul 1, 2013
    Messages:
    220
    Likes Received:
    203
    Location:
    Bosnia and Herzegovina
    Home Page:

    Just tested and work fine
     
  8. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    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?
     
  9. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Bump
    need to get 10 lines in 1 row and "VbCrLf" next 10 lines .. and so on
     
  10. helpinghand

    helpinghand BANNED BANNED

    Joined:
    Jul 15, 2013
    Messages:
    194
    Likes Received:
    13
    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
     
  11. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    NullReferenceException Was Unhandled!
    variable 'array' is used before it has been assigned a value.
     
  12. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    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.
     
    • Thanks Thanks x 1
  13. helpinghand

    helpinghand BANNED BANNED

    Joined:
    Jul 15, 2013
    Messages:
    194
    Likes Received:
    13
    Send me your email i will send complete project i made for this in vs 2010
     
  14. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Special thanks to helpinghand for his nice help really appreciate it mate :congrats:
     
  15. Macthetrix

    Macthetrix Regular Member

    Joined:
    Feb 21, 2013
    Messages:
    379
    Likes Received:
    390
    Occupation:
    The Boss
    Location:
    Silicon Valley
    What is the problem? Just add 10 linebreaks at the end of each loop

    for(i=0; i<10; i++)
    {
    Environment.NewLine;
    }
     
  16. sandrine10

    sandrine10 Power Member

    Joined:
    Apr 14, 2010
    Messages:
    621
    Likes Received:
    63
    Location:
    CyberLand
    Nice works as well.
     
  17. DataBots

    DataBots Newbie

    Joined:
    Sep 23, 2013
    Messages:
    16
    Likes Received:
    3
    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]
     
  18. dycero

    dycero Newbie

    Joined:
    Aug 15, 2013
    Messages:
    22
    Likes Received:
    7
    looks like this was already solved for you, if you still need help just let me know
     
  19. zohar

    zohar Newbie

    Joined:
    Jun 24, 2014
    Messages:
    44
    Likes Received:
    5
    Split & Mid. No other programming languages offer these functions, that is why I code VB.