Forum Discussion

amitbansal's avatar
amitbansal
Occasional Contributor
8 years ago

How to create java Arrays in TestComplete?

I am trying to use this java class http://wush.net/svn/mindprod/com/mindprod/csv/CSVSort.java in my test automation to sort a csv file. I am using JScript as my scripting lang.   Here is the info ...
  • HKosova's avatar
    8 years ago

    amitbansal wrote:

    when I run it, it gives me error  with msg "invalid procedure or argument"

    I think I need to pass Java Arrays to the function instead of Jscript array, not sure what the syntax would be for that. any help is greatly appreciated.


    You can create Java arrays using the java.lang.reflect.Array class. You need to add the following classes to project properties > Java Bridge > Java Classes:

     

    java.lang.reflect.Array

    java.lang.Class

     

    Here's how you can create an integer array with 2 elements:

    var intType = JavaClasses.java_lang.Class.forName("java.lang.Integer");
    var arrCols = JavaClasses.java_lang_reflect.Array.newInstance_2(intType, 2);
    arrCols.Items(0) = 31;
    arrCols.Items(1) = 35;

    Char and bool arrays can be created similarly - as arrays of types java.lang.Character and java.lang.Boolean.