Forum Discussion

windend's avatar
windend
Occasional Contributor
13 years ago

How to call a function of other script unit by method name as parameter in VB?

hello, I'm studying TestComplete to perpare for a new project. We are plan to build a framework on TestComplete for regression testing of web application. Is there some solution in VB in TestComplete as below Java code? We want to invoke functions in other script unit by function name as parameter. I have seen Runner.CallObjectMethodAsync method, but i'm not sure if it's suitable for our request. Thank you for your great help!



//Java Code Begin

 


Class cl = Class.forName("com.Common.KeywordHelper");



Class



partTypes[] = new Class[] { String.class, Integer.class,TestObject.class, String.class, String.class,String.class };


Object params[] = new Object[4];


Method mthd = cl.getMethod(methodName,partTypes);


result = (Boolean) mthd.invoke(new KeywordHelper(),(Object[]) params);



//Java Code end



4 Replies

  • windend's avatar
    windend
    Occasional Contributor
    hi Helen,



    Thank you for the reply! It does help us. I read the section you mentioned before, but i didn't find the statement as you post. It's great helpful.



    By the way, how to transfer parameters if the sub/function in Unit2 has parameters in this situation? i didn't find the solution in the support docment.



    Thank you.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Amy,



    Thanks for calling our attention to some missing information in the documentation. We'll improve it.



    To pass parameters to the Sub or Function being called, you need to embed them in the string passed to Execute/Eval:

    Execute "Call UnitName.SubWithParams(1, ""string"", True)" ' Using syntax with the Call keyword and parentheses

    Execute "UnitName.SubWithParams 1, ""string"", True" ' Syntax without the Call keyword and parentheses



    res = Eval("UnitName.FunctionWithParams(1, ""string"", True)")



    ' Inserting parameter values dynamically

    strFunctionCall = aqString.Format("UnitName.FunctionWithParams(%d, ""%s"", %s)", 42, "string", CStr(True))

    res = Eval(strFunctionCall)