"Object must be of type Double"

Hi!

I have an excel file with different columns, see the picture below.
image
I would like to get the highest value of Column 1. For this I used the excel application scope with read range with output “dt1”, after that an assign activity where Maxvalue = dt1.AsEnumerable().Max(Function(row) row(“Column 1”))

The Maxvalue variable is set to Object. When I use the write line activity to check it out, I get an error saying: “Object must be of type Double”. When I change the variable type to double, the assign activity will pop an error: Conversion from object to double is not allowed because of the Strict On option.

Can anyone help me with this?

Kind regards.

1 Like

Hi kblok, I had a look at this scenario and I was able to get an output when I pass Maxvalue.ToString to the Write line activity. In my case the variable type is still set as object. Are you converting the Maxvalue variable into any other types before or during the Write Line activity?

2 Likes

Hi Naveens,

Thank you for your quick respond!

I’m converting the Maxvalue to string in the write line activity, as you can see in the image below.


The Maxvalue is set to object aswell, when I run the proces I get the “Object must be of type Double” message. If I change the variable type to double, I’ll get the error in the assign activity.

2 Likes

Hi kblok, was able to find why the behavior was different for me. While I have an excel file without any blank spaces, it worked fine. The moment I added a blank row in between, I got the same error. Following is a screenshot of the excel I used which worked fine:

image

Adding a blank row on the second row and 4th row, gave me the same error.

2 Likes

Hi Naveens,

Thanks a lot! You solved the problem.
For anyone else having the same problem and has to work with a standard template where the empty rows are inevitable, first use the following assign activity to clear the empty rows:
dt.rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(""))).CopyToDataTable()

3 Likes

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