Forum Discussion

pmahesha's avatar
pmahesha
Occasional Contributor
13 years ago

Reading table values and comparing

I have an issue with comparing the values from a table (Reading one value at a time from table Dynamically). I use Java script.



Here is the Code for reading one value from second column in a table:



function test10()

{

  var tableIndex=59;

  HeaderTableAddress=Aliases.MainProcess.SwingObject("ea", "Dicom Tag Information", -1, 1).SwingObject("JRootPane", "", 0).SwingObject("null.layeredPane").SwingObject("null.contentPane").SwingObject("JPanel", "", 0).SwingObject("JScrollPane", "", 0).SwingObject("JViewport", "", 0).SwingObject("JTable", "", 0);

 

var value=HeaderTableAddress.wValue(tableIndex,2);

  if(value!=HeaderTableAddress.wValue(tableIndex,2))

  {

    Log.Error("Failed  Expected Value  = "+value+"  Actual = "+HeaderTableAddress.wValue(tableIndex,2));

  }

 

}



When I run this code, I get the failure. But values are correct as displayed below:



Failed  Expected Value  = 20091220  Actual = 20091220



So I used Trim.

var value=Trim(HeaderTableAddress.wValue(tableIndex,2));



It works fine as long as there is no Null characters in the table. When null character is encountered, I get error message:



Trim. Could Not convert variant of type (Dispatch) into type (String)



So what is the solution?

Q1. How to read and compare table values without using Trim (Note that table contains strings as well as numbers)

Q2. How to use Trim when there is a null?

5 Replies

  • Hi,



    Instead of using the != operator to compare your values, try using a property checkpoint which is more flexible.



    BTW, your code compares a value with itself. This looks quite strange:



    var value=HeaderTableAddress.wValue(tableIndex,2);

    if(value!=HeaderTableAddress.wValue(tableIndex,2))

  • pmahesha's avatar
    pmahesha
    Occasional Contributor
    Thank you for the reply.

    I know I am comparing the value itself. I gave only as an example just to show the problem I am getting with Trim. In real test, entire table values will be read first and stored in an array and compared  after doing certain operations on the application to see that table values are changed or not changed.



    I have gone through the use of Tables property. But I have one confusion.



    My table is not static. Value get changed during run time. Also it is not one table. I have an array of tables. That means I need to create an array of table object (If there is a provision) something like below:



    myTableArray=new Array();

    for(i=0;i<10;i++)   // Create 10 tables

    myTableArray=new Tables.myTable()



    How to do this?



    Here is my code outline look like:



    for(myIndex=0;myIndex<10;myIndex++)

    {



    Read the present values of the table and store in my TableArray[ myIndex]

    Do certain operation in the application.

    Verify that the table values are changed as per the need.

    }



    In the above case, I end up in creating and storing 10 table objects.





    Please suggest if there is a method to do this.



    Regards,



    Mahesha
  • Hi,



    To create multi-dimensional arrays, you need to declare an array and store arrays as its items. In your case, since you need to create an array of tables, you need to either create an array which will hold arrays which will hold arrays holding the values read from your tables.

    For example:

    ...

    var myTableArray = new Array();

    for(var i = 0; i < 10; i++) // if you have 10 grids

    {

    myTableArray = new Array();

    }

    ...




    This will create a two-dimensional array where you can store data from your grids. I don't know how they all are named in your application, so, I cannot write a generic loop. Code for saving data from each individual grid will look like this:

    ...

    var grid = // Obtain the grid control

    for(var row = 0; row < grid.wRowCount; row++)

    {

    var rowData = new Array();

    for(var col = 0; col < grid.wColumnCount; col++)

    {

    rowData.push(grid.wValue(row, col));

    }

    myTableArray[/*specify index here*/].push(rowData);

    }

    ...




    As a result, myTableArray holds an array of two-dimensional arrays which store the grid data.
  • pmahesha's avatar
    pmahesha
    Occasional Contributor
    But will this solve my problem with Trim (My first query)? Any other alternative to Trim? If I do not use Trim, comparison fails.
  • Hi,



    To solve your problem with Trim, you can check whether the value you want to pass to it is null before calling Trim. To do this, use the GetVarType method.