Forum Discussion

tmi5019's avatar
tmi5019
New Contributor
11 years ago
Solved

Increment number in text box using a for loop

Hello,



I have a test that loops using a for loop multiple times creating multiple individual entities. Each entity is given a name using a textbox. Is there a way to get TestComplete 9 to increment a number at the end of the entity's name for each loop? For example:

Entity # 1

Entity # 2

Entity # 3

etc.



I would like them to preferably be numbered with each loop that occurs.



Thank you!
  • I don't know an automatic way to do it but here's how I set it up in one keyword test:



    Use this for the name of the entity in a set_text or wherever you need it

    "Entity # " + aqConvert.IntToStr(Project.Variables.Entity_Counter)



    Entity_Counter is an integer variable (project or local, whatever you need)  that gets incremented in your loop 



    Your entity names will look like this

    Entity # 1

    Entity # 2

    Entity # 3





3 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    I don't know an automatic way to do it but here's how I set it up in one keyword test:



    Use this for the name of the entity in a set_text or wherever you need it

    "Entity # " + aqConvert.IntToStr(Project.Variables.Entity_Counter)



    Entity_Counter is an integer variable (project or local, whatever you need)  that gets incremented in your loop 



    Your entity names will look like this

    Entity # 1

    Entity # 2

    Entity # 3





  • karkadil's avatar
    karkadil
    Valued Contributor
    Do you mean sometnig like this?




      var str = "Entity # ";


      var resStr;


      


      for(var i = 0; i < 10; i++)


      {


        resStr = str + String(i);


        Log.Message(resStr);


      }

  • tmi5019's avatar
    tmi5019
    New Contributor
    Marsha, your response worked out well. I just needed to change the settext to code expression and it was working perfectly. Thank you!