Forum Discussion

lrix's avatar
lrix
Occasional Contributor
13 years ago

While Not/Table Variables issue - keeps resetting

I've got a Table Variable with 2 columns and 31 rows.  I use those values in the following loop...




Project.Variables.PayFrequency_02d.Iterator.Reset();


while (!Project.Variables.PayFrequency_02d.Iterator.IsEOF())


{


  .ComboBox.ClickItem(Project.Variables.PayFrequency_02d.Iterator("Frequency"));


  aqObject.CheckProperty(.ComboBox, "wItemList",   cmpContains, Project.Variables.PayFrequency_02d.Iterator("PayDateRule"));


  Project.Variables.PayFrequency_02d.Iterator.Next();

}



Any ideas why it doesn't run neatly through rows 1 to 31 (or 0 to 30).  It runs 1 to 12, then 2 to 15, and then all gets a bit more random looping between rows 3 and about 20?



I saw a similar issue last week with a data loop and a (not-particularly) large table using the Keyword Tests feature, which was when I was given the steer by a colleague to switch to scripting as it was deemed more stable. 



My workaround has been to break this down into 4 smaller tables and have 4 While! loops instead, which obviously doesn't look pretty and is giving me extra code to maintain.  (Even then one of those While! loops iterates through 1 to 4 then 1 to 8 (ie 12 iterations) when there are only 8 records in the table.



Thanks.

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Is there other code wrapped around this?  What it sounds like, to me, is that you're going through the loop and then an exception is firing breaking you out of the loop, and then it takes you back into this code again.  Is this part of a routine that is being called inside other routines?  It would be interesting to trace through this using the debugger to see if it is actually acting as random as you are observing or if there is some other underlying cause.
  • lrix's avatar
    lrix
    Occasional Contributor
    Thanks for the response.  But no, the code is not being called from another routine.  So if it did hit an exception I'd just expect it to die rather than start again.  When I broke the table variables down into 4 smaller tables (which I then had to call 4 times) it worked okay.



    I hit a similar problem later in the day where a !While loop ran through 4 columns, but the 6th or 7th iteration picked up row 7 column 1, row 7 column 2, row 7 column 3, but row 1 column 4.  Again, my workaround was to break this down into smaller columns and it worked ok.  All pretty frustrating.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What version of TC are you running, just in case there's a bug that has been fixed in later versions?



    In any case, I tried the following with a table variable with 2 columns and 31 rows.



    function TestTableLoop()





    {

        Project.Variables.MyTable.Iterator.Reset()

        while (!Project.Variables.MyTable.Iterator.IsEOF())

        {

             Log.Message(Project.Variables.MyTable.Iterator("Column1"))

             Log.Message(Project.Variables.MyTable.Iterator("Column2"))

             Project.Variables.MyTable.Iterator.Next()

        }

    }




    And it worked fine the first time.  This seems to tell me that the problem is not in the use of the table to run a loop or the table itself but may be more related to the code you are executing within the loop.  I don't personally see how code could cause the problem you're experiencing but, at this point, I've ruled out, at least generally speaking, table-driven loops being the cause of the problem.



    Another possibility... what exactly is in the data in your table?  Do you have special characters, etc, that you may be passing in that might confuse the "Click" or "Compare Property" command?




  • lrix's avatar
    lrix
    Occasional Contributor
    v 8.60.665.7



    I'm just passing alphanumerics, no special characters.



    Your code works on my side too, so that has restored my faith in the process.  I'll step through it as you've suggested and see if that highlights any errors on my part.



    It's a pretty clunky application I'm testing so it's more than conceivable that unexpected behaviour there is causing the issue.  But if I was stuck in an infinite loop or the loop bombed out I'd find this easier to get my head around.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Just an FYI, TC is up to an 8.70 release.  It might be worth it to try and upgrade and see if the problem goes away.  Upgrades between minor versions should be no financial cost.  Don't know what your company process is, though, for upgrading tools like this.
  • lrix's avatar
    lrix
    Occasional Contributor
    I can now narrow this down specifically to this field...

           aqObject.CheckProperty(Aliases.PSWizard.wndTfrmWizard.Panel.Panel.PSFormX.GroupBox.ComboBox, "wItemList", cmpContains, Project.Variables.PayFrequency_02d.Iterator("PayDateRule"));



    The loop works fine if I copy this out or put anything else in it.



    Also, as part of a general tidy up of my scripts in respect of the Aliases, I can see that the loop-error behaves differently depending on how I specify the component.  The following behaviour has been seen consistently (as opposed to the 'random' looping that I thought I was seeing yesterday).



    aqObject.CheckProperty(Aliases.PSWizard.wndTfrmWizard.Panel.Panel.PSFormX.GroupBox.ComboBox,
    "wItemList", cmpContains,
    Project.Variables.PayFrequency_02d.Iterator("PayDateRule")); >> loops through records 1-15, 1-16, 1-16, 1-16...indefinitely.



    aqObject.CheckProperty(Aliases.PSWizard.wndTfrmWizard.Panel.Panel.PSFormX.GroupBox.ComboBox,
    "wItemList", cmpContains,
    Project.Variables.PayFrequency_02d.Iterator("PayDateRule"));  >> loops through records 1-19, 2-21, 2-21, 2-21...indefinitely



    aqObject.CheckProperty(comboBox,
    "wItemList", cmpContains,
    Project.Variables.PayFrequency_02d.Iterator("PayDateRule"));  >>
    loops through records 1-20, 2-22, 2-22, 2-22...indefinitely



    Does that help shed any light?  Or is it a red-herring?

    I know I could use other data sources but storing them locally in the Table Variables seemed ideal.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It would be interesting to know what's in the PayDateRule value that is causing this kind of looping.  Considering that wItemList is typically a delimited string list with carriage returns seperating the items, I wonder if that may be messing things up a bit if your PayDateRule value also has some carriage return characters built in...