I ask the Inference Engine a question as follows, and want to obtain the first Fact, for the first Query (the question consists of 2 Atoms in the Query), if a result is returned.
strAnswer = IIf(InfEng.RunQuery(Question).Count > 0, InfEng.RunQuery(Question)(0)(0).ToString, "No Answer")
This throws an error
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"when the Query count = 0. In the 'Watch' window, it evaluates to 0, and has the message: Error & No children, when I open up the evaluated statement. When the query returns Facts, this works without a hitch.
I substituted .Any
, instead of Count, but that also did not work.
When I changed this to a standard If-Then-End If
, it works in all cases...and with .Count
& .Any
What am I doing incorrectly ?