Forum Discussion

newbie23's avatar
newbie23
Occasional Contributor
13 years ago

Unable to Add a row to table 2 dimensional variable programmatically

I was wondering, is there a way to add a row to a 2-dimensional table variable programmatically?



I was dissapointed to find that ".AddColumn" exists but ".AddRow" does not.  To me, ".AddRow" would be so much more helpful to have then being able to add a column programmatically (since I often work with data where I won't always know how many rows it will need but it always uses the same "columns").



Right now as a work-around, I just add a bunch of blank rows by default and then have an if statement for each test that uses the data in a "data-driven loop" to stop once it hits a blank row.



This work-around is pretty lame though, so if there is no way to add a row programmatically, can this at least be added as a feature request?



Thanks in advance :)
  • sastowe's avatar
    sastowe
    Super Contributor
    I can't remember for sure, but I think you just change the row number some how. I don't have access to TC right this second. But take a look into the help and see if there is a row count setting. Yah RowCount is the property. Does that work?
  • newbie23's avatar
    newbie23
    Occasional Contributor
    Thanks for the reply Stephanie,



    Unfortunatly, .RowCount only returns the total number of rows for the given table.  It won't allow you to set more rows.



    *Update*

    Nevermind, I just now got what you ment lol - I will give it a try and post back how it goes.
  • newbie23's avatar
    newbie23
    Occasional Contributor
    Unfortunately, that didn't work.



    It takes the expression, but when I output RowCount after setting it equal to 5, for example, it just goes back to its default :(
  • sastowe's avatar
    sastowe
    Super Contributor
    What version of Test Compelete are you using? If my memory serves, TC 7.2 did not allow the change of rows dynamically. You would enter your vaues directly into the project variable area, and that was fixed. In my TC 8.2 project, I am getting a row count from a database dynamically then setting the table variable row count to it




      s.RowCount = iPersonCount

      t.RowCount = iOrderCount



    Where the two variables iPersonCount and iOrderCount are integer variables that contain the number of rows in the underlying database that I am populating my table variable from. Works fine.

  • Hi Scott


    Variables of the Table type are not used as the permanent data storage. That is, you can modify them at runtime, but no changes are saved after the execution. Please go through the Variables of the Table Type topic to get more information on specifics of the Table variables.


    Ann

  • newbie23's avatar
    newbie23
    Occasional Contributor
    Ann - I already understand this concept, I am trying to modify the row count during execution....  In my example, I was using what Stephanie suggested and set the row count equal to 5 and outputted the row count in log.message during the execution, but it didn't work, it would still be the default rowcount.  Sorry for not explaining better :).



    Stephanie - I am using TestComplete 8 as well.....  Here is what I did in my example:



    (CustomerTempTable.rowcount = 1 by default before execution starts)





    During execution:



    Project.Variables.CustomerTempTable.rowcount = customerindex (customerindex is set to 5)



    log.message(Project.Variables.CustomerTempTable.rowcount)  - output is 1



    (I also tried just setting CustomerTempTable.rowcount equal to 5, but the output is still 1)



    Any idea's?
  • Hi Scott,


    I tried to reproduce the issue, but failed. Could you please create a sample project that I can use to investigate the issue and attach it here?


    Thanks in advance.

    Ann

  • sastowe's avatar
    sastowe
    Super Contributor
    Sorry Scott. I am going to be no help to you. It works in my project.
  • newbie23's avatar
    newbie23
    Occasional Contributor
    It's ok Stephanie, thanks for your comments and you ended up resolving my issue after all :)



    Ann, sorry for the late reply, but I was unable to reproduce this myself.  When I tried setting up what Stephanie suggested again, it worked.  So I am good now :)





    basic script in case anyone else is has the problem:



    1. In the main project, create a table folder called "test"

    2. Give it a column and a row



    3. run the following function:


    sub test()



      dim before, after

      before = Project.Variables.test.RowCount

     

      Project.Variables.test.RowCount = 5

     

      after = Project.Variables.test.RowCount

     

      log.message("before change: " & before & "after change: " & after)

     


    end sub



    4. Results should say: before change: 1 after change: 5)



    Thanks for the help :)