Google
 
We have moved to a http://siebelunleased.com Please visit there for updated posts

Thursday, October 11, 2007

NextRecord DeleteRecord - Use with caution!!

Number of times we have written code in which we have to traverse number of records in a loop and n number of times we have missed one important statement that results in our code to stuck in infinite loop. Yes, I am talking about the statement Object.NextRecord()

This statment is generally used at the end of the loop so that after all the processing is complete we move on to the next record in the record set and perform processing on the next record. I am giving a Psuedo code to explain that.

while(not end of recordset)

{

perform operation

recordset.NextRecord()

}


But here I am going to to tell you about a situation where doing a NextRecord(). will result in problems. Yes, I we are deleting the records in the loop then we don't need to use the NextRecord() function.


Reason for that is using DeleteRecord() results in pointer to moved to next record automatically and if we use NextRecord then it will result in skipping of the last record we are trying to delete. Pseudo to explain this

while(not end of RecordSet)

{

do processing

recordset.DeleteRecord();

// recordset.NextRecord(); // no need to use next record as delete will automatically move the pointer to next line

}

Hope this tip is helpful. Happy Scripting :)

0 Comments:

You Might want to read following articles also.