Hi,
I am using for each loop and if function. I am trying to compare if current row is the same with previous row using:
dt.rows.indexof(row)>0 and row(“Company Name”).ToString = dt(dT.Rows.IndexOf(row) - 1).item(“Company Name”).ToString
however, i encounter error “If: Object reference not set to an instance of an object.” and i do not know why.
Pls help, thank you
Yoichi
(Yoichi)
2
Hi,
Can you try AndAlso instead of And as the following?
dt.rows.indexof(row)>0 AndAlso row("Company Name").ToString = dt(dT.Rows.IndexOf(row) - 1).item("Company Name").ToString
Regards,
This works! but may i understand why we should be using AndAlso instead of And?
Yoichi
(Yoichi)
4
Hi,
It’s because AndAlso
evaluate the expression as short-circuiting. (And And
is non-shortcircuiting) Please see the following in details.
Regards,
system
(system)
Closed
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.