Windows conversions throws Compiler error BC36641

Compiler error(s) encountered processing expression “MyDataTable.AsEnumerable.Sum(Function(row) Cint(row(3)))”.(2) : error BC36641: Lambda parameter ‘row’ hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a query expression.

Its in an assign activity where I only need rows with a valid number… DTOnlyNeededRecords.AsEnumerable.Sum(Function(row) Cint(row(3)))

Is there another way of doing this - basically when it is not an Int - the try catch will assign it a 0 and continues…

1 Like

Hi @ton_roelandse

Can you try like this please

MyDataTable.AsEnumerable.Sum(Function(x) if(IsNumeric(x(3).ToString),Cint(x(3).ToString),0))

This gives you a double value with sum

I only changed row to x so that it does not interfere with any other internal variable

This basically gives the sum of rows in 4th column when rows have valid numbers

If you want all rows which are non zero in column 4 then use this

MyDataTable.AsEnumerable.Where(Function(x) IsNumeric(x(3).ToString)).CopyToDataTable

This gives you a datatable

Cheers

Thanks Anil - I will try your first outlined suggestion -

Still would like to understand though why this is not accepted after the conversion to Windows - a topic for another day.

1 Like

Hi @ton_roelandse

One reason might be not including .ToString after row(3) because in the latest dot net it expects the datataypes to be defined and proper

Cheers

that would make sense - one more question though…

You added the If(isNumeric) test - however I want it to error out if it is Null, or not numeric - this way the other logic stays intact, and minimizes other changes I have to make. Any suggestion on how that would look like…?

Hi @ton_roelandse

I added it becasue if there are blank values in the column then it can be ignored, but if you want it to error out then just remove that condition and it would throw error when a non numeric character or a blank value is found

MyDataTable.AsEnumerable.Sum(Function(x) Cint(x(3).ToString))

Hope this answers you query

cheers

Thanks - Marked as solution!

Have a good one…

1 Like

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