When I use some statement like this io_ExtractionResults.ResultsDocument.Fields(10).Values(0).Value I get an error saying index was out of the bounds of array.
to avoid this, I tried adding an “if” condition saying io_ExtractionResults.ResultsDocument.Fields.Count > 10
and another method not string.IsNullOrEmpty(io_ExtractionResults.ResultsDocument.Fields(10).Values(0).Value) and io_ExtractionResults.ResultsDocument.Fields(10).Values(0).Value.ToUpper.Contains(“string value”)
…both expressions are processed, then the result is generated. So even if the first expression is false, it still has to process the second expression to generate the boolean result.
In this case you should use AndAlso. It’s what is called “short circuiting.” If the first expression is false it doesn’t process the second expression.
Hi Arpan, for this example, there’s surely more than 10 index fields in the document, strange that it comes like this. Can it be solved if we don’t add the field as an index but rather as a field= “” value?
You’re checking if .Fields.Count is greater than 10 and it is, but you’re getting .Fields(10).Values(0) so the index error probably means there are no elements in .Values
The AndAlso means the expression after it is only processed if the expression before it returns true. So out_ExtractionResults.ResultDocument.Fields(10).Values.Count > 0 is only processed if out_ExtractionResults.ResultDocument.Fields.Count > 10 is true, and string.IsNullOrEmpty(out_ExtractionResults.ResultsDocument.Fields(10).Values(0).Value) is only processed if the previous two expressions are true.