INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VB Script to convert TWO delimted columns to multiple rows.

VB Script to convert TWO delimted columns to multiple rows.

(OP)
I have the following data:

KeyField,listField1,ListField2
123,"122,345,321","2,3,1"
124,"222,221","5,2"

I need to convert it to:

KeyField,ListItem1,ListItem2
123,122,2
123,345,3
123,321,1
124,222,5
124,221,2

I have managed to do just one column resulting in:

KeyField,ListItem1,ListItem2
123,122,"2,3,1"
123,345,"2,3,1"
123,321,"2,3,1"
124,222,"5,2"
124,221,"5,2"

I need the ListField2 to be split out too...


The above result was using a For Each loop:

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim keyField As Integer = Row.KeyField
Dim itemList As String = Row.ListField
Dim delimiter As String = ","

If Not (String.IsNullOrEmpty(itemList)) Then

Dim inputListArray() As String = _
itemList.Split(New String() {delimiter}, _
StringSplitOptions.RemoveEmptyEntries)

For Each item As String In inputListArray
With Output0Buffer
.AddRow()
.KeyField = keyField
.ListItem = item
.ListItem2 = Row.ListField2

End With
Next

End If

End Sub


Many thanks in advance,

Chris

RE: VB Script to convert TWO delimted columns to multiple rows.

(OP)
I have now managed to sort this with the below code:

Dim keyField As Integer = Row.KeyField
Dim itemList As String = Row.listField1
Dim itemList2 As String = Row.ListField2
Dim delimiter As String = ","

If Not (String.IsNullOrEmpty(itemList)) Then

Dim inputListArray() As String = itemList.Split(New String() {delimiter}, StringSplitOptions.RemoveEmptyEntries)
Dim inputListArray2() As String = itemList2.Split(New String() {delimiter}, StringSplitOptions.RemoveEmptyEntries)
Dim counter As Integer = 0

For Each item As String In inputListArray
With OutputBuffer
.AddRow()
.KeyField = keyField
.ListItem = item
.ListItem2 = inputListArray2.GetValue(counter)
counter = counter + 1
End With
Next
End If

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close