Wednesday, 22 October 2008

Quirky IsEOF()

The IsEOF() function works a little different to how you'd expect it, and without understanding this function, you may end up missing your last entered customer, or invoice.

IsEOF() is flagged true after reading the second-last record. That is to say, if you have 10 records, after reading record 9, then IsEOF() becomes true. This means you can still read record 10, but no more.

The code example in the download from the website, actually misses this point, so here's how to fix it:

SageDataObject50.SalesRecord srCustomer50 = (SageDataObject50.SalesRecord)ws50.CreateObject("SalesRecord");
bool blnLast = false;
strDescription = srCustomer50.Fields.Item(ref objDescription).Value.ToString();
if (blnLast) break;
blnLast = srCustomer50.IsEOF();

The code added is highlighted in brown. Note how IsEOF is flagged before the last record is read.

No comments: