SetNextRow explanation - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP) +--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners) +--- Thread: SetNextRow explanation (/Thread-SetNextRow-explanation) |
SetNextRow explanation - vijayendra.shukla - 02-24-2010 Hi, Code: DataTable("MyCol","Action1")=123456 when i run this code 1255 is getting written in 3rd row of Action1 datasheet. But when i run this code step by step (F10), 1255 is getting written in 2nd row of the Action1 datasheet. Can anyone explain me why this is happening???? RE: SetNextRow explanation - Saket - 02-25-2010 I just wonder how you are getting 1255 in second row. I have gone through the statements above and feel that it will always write 1255 in the the third row only unless you have not set the current row / commented your statements anywhere in betwenn again apart from the mentioned. if the current row is not set at the beginning first statement DataTable("MyCol","Action1")=123456 will always write at the first row in second statement you will get the value as '1' for row which you use to set the current row increasing with 1 i.e. now the current row is 2 in the next statement you are again setting the current row as next row, which means the current row is now 3 so the last statement will always write in row 3. makes sense? RE: SetNextRow explanation - vijayendra.shukla - 02-25-2010 hi Saket, Yeah, thanks. That makes sense. But if you comment the 3rd line i.e. try this code Code: DataTable("MyCol","Action1")=123456 according to your explanation, this should write 1255 in 2nd row. But this is writing in the first row itself. why is it so?? RE: SetNextRow explanation - Saket - 02-25-2010 Hi Vijyendra, you will need to understand the difference between the two i.e. SetCurrentRow and SetNextRow SetCurrentRow sets the row specified as the current row in your Data Table, where SetNextRow sets the row after the active row as the new current row in the Data table. If the current row is the last row in the Data Table, this sets the first row in the Data Table as the new current row. in your case here, Code: DataTable("MyCol","Action1")=123456 Code: DataTable("MyCol","Action1")=123456 if you put a SetNextRow again it will be back to the first row again as the current active is the last row Code: DataTable("MyCol","Action1")=123456 to better understand this, have a look at the below code Code: DataTable.SetCurrentRow(1) applying SetNextRow in the second statement activates row 2 as the active row. you can not use setnext row alone. try this Code: DataTable.GetSheet("Action1").SetNextRow on the second setnextrow stament it goes back to the first row use SetNextRow only when the next row contains at least one value and use it when you are retriving values from Data table. while setting values to datatable SetCurrentrow is sufficient, applying SetNextRow may create confusions. Hope I am able to make it clear to you RE: SetNextRow explanation - vijayendra.shukla - 02-25-2010 Perfect answer!!! This was very helpful indeed! 10/10 Cheers, Vijayendra |