Keep row number

Hi all,

Im having trouble making QTP do a For loop with stuff for 100 rows in a DataTable, then do different stuff 1 time and do the first stuff again for the next 100 rows (ie row 101-200), rinse and repeat with 100 rows each time. My problem is that it starts at row 2 after doing the code first time and I need it to continue from row 101 instead.

For clarification I added a msg box in the code and what im trying to accomplish is for that to add 1 each time, also between running full circle in the code (ie for each 100 rows). So lets say after doing 400 rows the msgbox should say 400 and the "do different stuff" code would then have been done 4 times.

Dim x

For x = 1 To 100

'Do stuff
msgbox DataTable.GlobalSheet.GetCurrentRow

Next

'Do different stuff 1 time and then start the For loop again from row 101

 

Is it in any way possible to "save" the row number and continue from that after doing the full code?

I would really appreciate any effort spend helping :-)

 

Using QTP 11 and in settings its set to run on all rows

 

Parents Reply Children
  • Thanks for the suggestions.

     

    Not sure how the suggestion with the function is meant to work though, cause i will still have to make the function run only once every 100th time. How would that code look?

     

    I am currently waiting for my company to install latest version of UTF and that might behave different than QTP that im using now, so i ll wait with messing with this until then.

     

    I did try the DataTable.SetCurrentRow(RowNumber) earlier but that gets reset as well.

     

    But I will try to save the variable in a sheet and see if that can work once i get the new installation.

     

    Cheers :)

  • Thanks for the suggestions.

     

    Not sure how the suggestion with the function is meant to work though, cause i will still have to make the function run only once every 100th time. How would that code look?

     

    I am currently waiting for my company to install latest version of UTF and that might behave different than QTP that im using now, so i ll wait with messing with this until then.

     

    I did try the DataTable.SetCurrentRow(RowNumber) earlier but that gets reset as well.

     

    But I will try to save the variable in a sheet and see if that can work once i get the new installation.

     

    Cheers :)

  • Thanks for the suggestions.

     

    Not sure how the suggestion with the function is meant to work though, cause i will still have to make the function run only once every 100th time. How would that code look?

     

    I am currently waiting for my company to install latest version of UTF and that might behave different than QTP that im using now, so i ll wait with messing with this until then.

     

    I did try the DataTable.SetCurrentRow(RowNumber) earlier but that gets reset as well.

     

    But I will try to save the variable in a sheet and see if that can work once i get the new installation.

     

    Cheers :)

  • Here is a quick way to do it.  It's probably not the best way, but it may work in your situation.  In your data spreadsheet, on every hundreth row set a flag that let's QTP know to "do different stuff 1 time" as you mentioned.  In my example below, I created a new column in the spreadsheet called "MyColumnFlag" on each hundreth row I put the text "END" in the Excel cell.  If you have lots of rows (like in the 1,000s) then this might not be a good approach, but if you're talking a few hundred or less then it may work for you.  Be sure to set the run time setting to "Run one iteration only".  Hope this helps.

     

    Dim x, rowcount
    DataTable.ImportSheet "C:\Temp\MySpreadsheetExample.xls""Global""Global"
    rowcount = DataTable.GlobalSheet.GetRowCount
    For x = 1 To rowcount
        DataTable.GetSheet("Global").SetCurrentRow(x)
        'Do stuff
        If DataTable.Value("MyColumnFlag""Global") = "END" Then
            msgbox "This was the hundredth row."
            'Do different stuff 1 time and then start the For loop again from row 101
        End If
        DataTable.GetSheet("Global").SetNextRow
    Next

  • The 100th cell value might work, but I do have a lot of rows, like 10.000, but of cause its just 1 time i have to set it up.

     

    If the other suggestions i havent tried yet fails me, i might go for that one.

     

    Still waiting for the installation of UTF.

     

    Thanks :)

  • The 100th cell value might work, but I do have a lot of rows, like 10.000, but of cause its just 1 time i have to set it up.

     

    If the other suggestions i havent tried yet fails me, i might go for that one.

     

    Still waiting for the installation of UTF.

     

    Thanks :)

  • The 100th cell value might work, but I do have a lot of rows, like 10.000, but of cause its just 1 time i have to set it up.

     

    If the other suggestions i havent tried yet fails me, i might go for that one.

     

    Still waiting for the installation of UTF.

     

    Thanks :)

  • I have a suggestion, but need a clarification first.

    Is the thing you do every 100th row the same thing or different?

    I think you could maybe do this by using a Global datasheet and an Action datasheet.

     

    The Action datasheet would include the 10,000 rows for which you want to perform some activity for every block of 100 rows. That activity would be defined in a separate Action to which that datasheet would be associated.

     

    The Global datasheet would have one row for every 100 rows in your Action sheet. So, if your Action sheet has 10,000 rows, then your Global sheet would have 100.

     

    The Global sheet drives the overall iteration of your main test script. Within the main test script, in each of its iterations you execute the activity that you want to execute for every 100th row. Then you insert a call to your Action, telling it to iterate through rows n through n 99 of your Action datasheet.

     

    Your main test would iterate 100 times (the number of rows in the Global datasheet). Within each of those iterations, you would iterate 100 times through the  secondary Action. You could even make the starting and ending rows for the secondary action part of the row data in your Global sheet.

     

    I do something similar in my testing, but I use an External Action and have to use commands to load the DataTable that goes with the External Action. I choose to store my datatables separate from my test scripts. You might be able to do this with datatables stored as part of the test script, though.

  • I have a suggestion, but need a clarification first.

    Is the thing you do every 100th row the same thing or different?

    I think you could maybe do this by using a Global datasheet and an Action datasheet.

     

    The Action datasheet would include the 10,000 rows for which you want to perform some activity for every block of 100 rows. That activity would be defined in a separate Action to which that datasheet would be associated.

     

    The Global datasheet would have one row for every 100 rows in your Action sheet. So, if your Action sheet has 10,000 rows, then your Global sheet would have 100.

     

    The Global sheet drives the overall iteration of your main test script. Within the main test script, in each of its iterations you execute the activity that you want to execute for every 100th row. Then you insert a call to your Action, telling it to iterate through rows n through n 99 of your Action datasheet.

     

    Your main test would iterate 100 times (the number of rows in the Global datasheet). Within each of those iterations, you would iterate 100 times through the  secondary Action. You could even make the starting and ending rows for the secondary action part of the row data in your Global sheet.

     

    I do something similar in my testing, but I use an External Action and have to use commands to load the DataTable that goes with the External Action. I choose to store my datatables separate from my test scripts. You might be able to do this with datatables stored as part of the test script, though.

  • I have a suggestion, but need a clarification first.

    Is the thing you do every 100th row the same thing or different?

    I think you could maybe do this by using a Global datasheet and an Action datasheet.

     

    The Action datasheet would include the 10,000 rows for which you want to perform some activity for every block of 100 rows. That activity would be defined in a separate Action to which that datasheet would be associated.

     

    The Global datasheet would have one row for every 100 rows in your Action sheet. So, if your Action sheet has 10,000 rows, then your Global sheet would have 100.

     

    The Global sheet drives the overall iteration of your main test script. Within the main test script, in each of its iterations you execute the activity that you want to execute for every 100th row. Then you insert a call to your Action, telling it to iterate through rows n through n 99 of your Action datasheet.

     

    Your main test would iterate 100 times (the number of rows in the Global datasheet). Within each of those iterations, you would iterate 100 times through the  secondary Action. You could even make the starting and ending rows for the secondary action part of the row data in your Global sheet.

     

    I do something similar in my testing, but I use an External Action and have to use commands to load the DataTable that goes with the External Action. I choose to store my datatables separate from my test scripts. You might be able to do this with datatables stored as part of the test script, though.