Invoke Code error - For each row and IF statements

I have build the below code in side Invoke code( VBnet). There is a (statement expected error) coming at the end of if block and after next( row 21 to23)
Test6.xaml (6.2 KB)
. Please refer to the below screenshot:

image

Dim table As New DataTable
table.Columns.Add(“Agent ID”, GetType(String))
table.Columns.Add(“Fatal”, GetType(Integer))
table.Columns.Add(“Non-Fatal”, GetType(Integer))

Dim table2 As New DataTable
table2 = dt2.Select("[Agency]=‘Airan’ AND [PrePostCol] =‘Post’ AND [Audit result] = ‘FAILED’ AND [Audit Date]=" + strAuditDate).CopyToDataTable

Dim table3 As New DataTable
table3 = table2.DefaultView.ToTable(True,“Agent ID”)

Dim row1 As DataRow
For Each row1 In table3.Rows
Dim strAgent As String
strAgent = row1.Item(0).ToString
Dim noOfFatal As Integer = 0
Dim noOfNonFatal As Integer = 0
For Each row2 As DataRow In table2.Rows
If(row1.Item(“Agent ID”)= row2.Item(“Agent ID”)) Then
If(row2.Item(“Fatal/Non-Fatal Error”)) Then noOfFatal = noOfFatal + 1 End If
If(row2.Item(“Fatal/Non-Fatal Error”)) Then noOfNonFatal = noOfNonFatal + 1 End If
End If
Next row1
table.Rows.Add( strAgent, noOfFatal, noOfNonFatal)
noOfFatal = 0
noOfNonFatal = 0
Next row1

out_table = table

Can you tell me what is the error for? I have checked the syntax for IF and For each seems ok.

.xaml is attached

@shrayud

Try below code

Dim table As New DataTable
table.Columns.Add(“Agent ID”, GetType(String))
table.Columns.Add(“Fatal”, GetType(Integer))
table.Columns.Add(“Non-Fatal”, GetType(Integer))

Dim table2 As New DataTable
table2 = dt2.Select("[Agency]=‘Airan’ AND [PrePostCol] =‘Post’ AND [Audit result] = ‘FAILED’ AND [Audit Date]=" + strAuditDate).CopyToDataTable

Dim table3 As New DataTable
table3 = table2.DefaultView.ToTable(True,“Agent ID”)

Dim row1 As DataRow
For Each row1 In table3.Rows
Dim strAgent As String
strAgent = row1.Item(0).ToString
Dim noOfFatal As Integer = 0
Dim noOfNonFatal As Integer = 0
For Each row2 As DataRow In table2.Rows
If(row1.Item(“Agent ID”)= row2.Item(“Agent ID”)) Then
If(row2.Item(“Fatal/Non-Fatal Error”)) Then
noOfFatal = noOfFatal + 1
End If
If(row2.Item(“Fatal/Non-Fatal Error”)) Then
noOfNonFatal = noOfNonFatal + 1
End If
End If
Next row1
table.Rows.Add( strAgent, noOfFatal, noOfNonFatal)
noOfFatal = 0
noOfNonFatal = 0
Next row1

out_table = table

1 Like

Thanks

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.