2012-01-17 173 views
0

我有以下代碼工作正常,並做它的目的。但是我的源數據有一條線添加到最底部,它使這個事情破裂。當我去和刪除最後一行時,這段代碼工作正常。我不想每天都手動修改這個腳本運行的文件。以下是代碼。有沒有什麼辦法可以忽略我輸入的最後一行,並處理其餘部分。我知道它是一個簡單的條件if-else,但我沒有任何關於.net的線索,而有人幫我編寫了這段代碼。提前致謝。vb.net代碼條件邏輯

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 

取樣輸入數據:643492,PV STRIP 1X1 UTILITY UP ,, 56,393454 最後輸入文件的臺詞: 「EndDb」

回答

1

像這樣的東西應該做的伎倆:

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 
+0

工作完美。謝謝! – rvphx 2012-01-17 22:33:09