Topic
  • 3 replies
  • Latest Post - ‏2014-04-03T23:48:09Z by A_Alers
A_Alers
A_Alers
8 Posts

Pinned topic Iterating folders

‏2014-04-03T01:55:26Z |

The following script is suppose to count for each module named "My Module" in each folder the total objects who's attribute satisfies the condition as in the script.  The problem with this script is that it counts the totals by folder. 

For example:

folder 1 has My Module with a total of 10 objects that satisfies the condition

folder 2 has 5 objects that satisfies the condition.

The output I am getting is:

folder 1: 10

folder 2: 15 (This should be 5 but it's counting the previous folder total.

Can someone help me identify what I am doing wrong?

Object o
Item i
string modName, fullModName, ObjType, attName, itemType, folderName
Project P = current
Folder f = current

for i in p do{
    folderName = name(f)
 itemType = type i
 if(itemType == "Formal"){
  fullModName = fullName(i)
  modName = name(i)
  if(modName == "MyModule"){
   m = read(fullModName, false)
   for o in m do{
    ObjType = o."Object Type"
    attName = o."testAttribute"
    if(ObjType=="test" && attName == "test method"){
     iReqCount++
    }
   }
  print folderName" There are: " iReqCount++""" Test Methods\n"
  close(m)
  }
 }
}

 

  • PRM
    PRM
    33 Posts
    ACCEPTED ANSWER

    Re: Iterating folders

    ‏2014-04-03T03:44:13Z  

    If I'm not mistaken, you have not reset the iReqCount variable to zero at the end of the loop through objects in a formal module. Consequently its value just keeps on compounding after each time you have looped through a module. Maybe enter iReqCount = 0 between lines 23 and 24 which will reset it back to zero before the object count starts in the next module.

    Probably a good idea to also declare iReqCount with all of the other variable decalrations at the top and give it an initial value of zero.

     

    Paul Miller
    Melbourne Australia 

  • llandale
    llandale
    3035 Posts
    ACCEPTED ANSWER

    Re: Iterating folders

    ‏2014-04-03T18:08:00Z  
    • Yes set iCount, but I'd do it near the top between #14 and #15.
    • perhaps print "modName" instead of "folderName".
    • open the standard view: m = read(fullModName, false, true)
  • PRM
    PRM
    33 Posts

    Re: Iterating folders

    ‏2014-04-03T03:44:13Z  

    If I'm not mistaken, you have not reset the iReqCount variable to zero at the end of the loop through objects in a formal module. Consequently its value just keeps on compounding after each time you have looped through a module. Maybe enter iReqCount = 0 between lines 23 and 24 which will reset it back to zero before the object count starts in the next module.

    Probably a good idea to also declare iReqCount with all of the other variable decalrations at the top and give it an initial value of zero.

     

    Paul Miller
    Melbourne Australia 

  • llandale
    llandale
    3035 Posts

    Re: Iterating folders

    ‏2014-04-03T18:08:00Z  
    • Yes set iCount, but I'd do it near the top between #14 and #15.
    • perhaps print "modName" instead of "folderName".
    • open the standard view: m = read(fullModName, false, true)
  • A_Alers
    A_Alers
    8 Posts

    Re: Iterating folders

    ‏2014-04-03T23:48:09Z  
    • llandale
    • ‏2014-04-03T18:08:00Z
    • Yes set iCount, but I'd do it near the top between #14 and #15.
    • perhaps print "modName" instead of "folderName".
    • open the standard view: m = read(fullModName, false, true)

    Thank you both!! It worked!