0

I have the following piece of code which works fine and does what it is intended for. But my source data has a line added to the very bottom and it makes this thing break. When I go and delete that last line, this code works fine. I dont want manually modify the file everyday this script runs. Following is the code. Is there any way I can ignore the last line of my input and process the rest of it. I know its a simple conditional if-else, but I dont have any clue about .net and someone else helped me write this code. Thanks in advance.

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim strRow As String
    Dim strColSeperator As String
    Dim rowValues As String()
    strRow = Row.Line.ToString()
    If strRow.Contains(",") Then
        strColSeperator = (",")
    ElseIf strRow.Contains(";") Then
        strColSeperator = ";"
    End If

    rowValues = Row.Line.Split(CChar(strColSeperator))
    Row.Code = rowValues.GetValue(0).ToString()
    Row.Description = rowValues.GetValue(1).ToString()
    Row.Blank = rowValues.GetValue(2).ToString()
    Row.Weight = rowValues.GetValue(3).ToString()
    Row.Scan = rowValues.GetValue(4).ToString()

End Sub

Sample input data: 643492,PV STRIP 1X1 UTILITY UP,,56,393454 Last line of the input file: "EndDb"

1 Answer 1

1

Something like this should do the trick:

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
    Dim strRow As String
    Dim strColSeperator As String
    Dim rowValues As String()
    strRow = Row.Line.ToString()
    If strRow.Contains(",") Then
        strColSeperator = (",")
    ElseIf strRow.Contains(";") Then
        strColSeperator = ";"
    End If

    rowValues = Row.Line.Split(CChar(strColSeperator))
    If (rowValues.Length > 1) Then
    Row.Code = rowValues.GetValue(0).ToString()
    Row.Description = rowValues.GetValue(1).ToString()
    Row.Blank = rowValues.GetValue(2).ToString()
    Row.Weight = rowValues.GetValue(3).ToString()
    Row.Scan = rowValues.GetValue(4).ToString()
    End If

End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.