Forum Discussion

ALBERTO_SERRANO's avatar
ALBERTO_SERRANO
New Contributor
11 years ago

Call script (VBScript) with ByRef args from KeywordTest

Hi



I'm trying to call a function (VBScript) from a KeyWordTest passing two arguments ByRef







In the call I pass two local variables LibRef and TpmCount to DllFunction2. The execution finishes Ok, the LastResult is true, but TpmCount (local KeywordTest variable) is not updated when the function call is finished







Am I missing something??



Many thanks in advance

Kindest regards, Alberto









  • Hi Alberto,



    ByRef doesn't work with project, project suite and keyword test variables. You need to access the variable directly to change its value:



    Function DllFunction2(Lib, CntVariableName)

      ...

      If Result Then

        KeywordTests.Test1.Variables.VariableByName(CntVariableName) = Count

      End If

      ...

    End Function



    and call the function like this:

    Run Script Routine        DLLFunction2        Variables.LibRef, "TpmCount"




    You can use project variables instead of keyword test variables to avoid hard-coding the keyword test name inside the script function.
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Alberto,



    ByRef doesn't work with project, project suite and keyword test variables. You need to access the variable directly to change its value:



    Function DllFunction2(Lib, CntVariableName)

      ...

      If Result Then

        KeywordTests.Test1.Variables.VariableByName(CntVariableName) = Count

      End If

      ...

    End Function



    and call the function like this:

    Run Script Routine        DLLFunction2        Variables.LibRef, "TpmCount"




    You can use project variables instead of keyword test variables to avoid hard-coding the keyword test name inside the script function.
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Alberto



    I think you might need to use the 'Eval' statement in this instance.  It's been a while since I read up on it, but something like this in your function might work better:





    Result = eval(Lib & ".TpmLibGetCountAvailableTpms(Count)")





    Regards

    Stephen.
  • Hi Stephen



    Thanks for the reply

    I think I didn't explain the problem very well

    The call Result = Lib.TpmLibGetCountAvailableTpms(Count) finishes OK. Result is 1 (expected) and Count is 1 (expected)

    Cnt = Count is executed and Cnt gets value 1



    The problem is after the call returns, in the keywordtest, Variables.TpmCount is 0. That means ByRef Cnt definition in DllFunction2 is not working?



    I hope it is more clear now



    Regarding eval...help system says that it is another possible way of calling a routine defined in another unit, does not seem to be mandatory. Am I right?



    Many thanks in advance