Join multiple rows in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bjorn
    New Member
    • May 2007
    • 1

    #1

    Join multiple rows in VB

    Hi

    My name is Bjorn and I have a VB question:

    How do I join multiple rows in VB?
    Example
    I have the data in a format like this:

    Code:
    	result 1	result 2
    11104	8	
    11104		1
    11105	2	
    11105		4
    I would like to have the data like this

    Code:
    	result 1	result 2
    11104	8	1	
    11105	2	4
    I really appriciate any help I can get. I am not well oriented in VB
    Thanks
    Bjorn
    Last edited by Killer42; May 3 '07, 03:11 AM. Reason: Added [CODE] tags to preserve formatting
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by Bjorn
    Hi

    My name is Bjorn and I have a VB question:

    How do I join multiple rows in VB?
    Example
    I have the data in a format like this:

    result 1 result 2
    11104 8
    11104 1
    11105 2
    11105 4

    I would like to have the data like this

    result 1 result 2
    11104 8 1
    11105 2 4

    I really appriciate any help I can get. I am not well oriented in VB
    Thanks
    Bjorn
    Hello, Bjorn!

    Is this VB 6 you are refering to?

    Welcome!

    Dököll

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by Dököll
      Is this VB 6 you are refering to?
      And what sort of data are we referring to? Is this something in a text file? An array? An Excel worksheet? A database? A big textbox? Something else?

      A general algorithm to handle this might be something along the lines of...
      Code:
      Read each line
        If the first part is the same as the previous line
          Add the second part to our output line
        Else
          Write out the output line (if any)
          Clear the output line
          Put the current line into the output line
        End If
      End of loop

      Comment

      Working...