Forum Discussion

mcastellanos's avatar
mcastellanos
Occasional Contributor
9 years ago
Solved

Call using USEUNIT in vbscript does not work

I have function1(param1) defined in script Unit1 and I want to call function1(param1) from script Unit2. Thus, I have done the following according to documentation:

 

'In Unit2 script, did

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'USEUNIT Unit1

 

function1(param1) 'Method 1

 

Unit1.function1(param1) 'Method 2

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

None of the above methods worked. Am I missing something?

Any input will be greatly appreciated.

  • There is something about naming conventions for USEUNIT calls which I can't quite recall?

     

    Hang on ....

     

    Got it.

     

    https://support.smartbear.com/viewarticle/73884/#Calling

     

    (The second bullet point)

     

    If the function name and unit name are the same, the call will only work if prefixed with the unit name. Sounds like whats happening to you.

7 Replies

  • mcastellanos's avatar
    mcastellanos
    Occasional Contributor

    Correction needs to be made.

     

    Method 2 works; however, Method 1 does not.

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      At the first glance it should work... Could you elaborate what does 'does not work' mean? Any message/warning/error in the log? If you insert some Log.Message() call into the function1 in Unit1, is this message present in the log? What happens if you put a breakpoint in Unit2 and then Step Into ?

       

      Also, what is the actual code of Unit2?

      If you provided complete code, than I would treat the observed behavior as the expected one:

      -- script code is executed by the VBScript runtime;

      -- VBScript runtime treats 'USEUNIT clause as a regular comment and thus has no idea about Unit1;

      -- function1() in this case might be treated as an unknown function and just skipped.

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        There is something about naming conventions for USEUNIT calls which I can't quite recall?

         

        Hang on ....

         

        Got it.

         

        https://support.smartbear.com/viewarticle/73884/#Calling

         

        (The second bullet point)

         

        If the function name and unit name are the same, the call will only work if prefixed with the unit name. Sounds like whats happening to you.

    • NisHera's avatar
      NisHera
      Valued Contributor

      don't know how it's working in VB since I'm into jScripting

      But it's a great thing that method 1 not working
      imagine a case you are calling UNIT X and UNIT Y and both have function1(param1)