Forum Discussion

adrian_g's avatar
adrian_g
Occasional Contributor
15 years ago

Is there a way to return the name of the current sub routine or function?

Hi All,



Is there a way to return the name of the current sub routine or function that is being run. It would be nice to enter into the log.



I am currently coding in VB Script.



I assume there is no way to do it using VB script but is there a TestComplete inbuilt function?



Thanks  heaps,

Adrian
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi,


     


    I've added your votes. 


    Manfred, thanks for sharing your solution.


     

    • Alice's avatar
      Alice
      Occasional Contributor

      Please add my vote as well!

  • katven's avatar
    katven
    New Contributor

    +1 for this feature. 

     

    Kindly add my vote too. 

  • I am also trying to figure out a way to know the current script name. We are launching TestExecute with Bamboo using command line. I think we can use 

    BuiltIn.ParamStr
    • meinTest's avatar
      meinTest
      Occasional Contributor

      For JavaScript, I found the following workaround. Maybe it will help others.

      I create a try-catch block. Within the try I provoke an exception, this one I catch-up with the catch and read-out the function name in the stack.

       

      Note: this also works across several units -> USEUNIT

      function getCaller(){
        let arrStackLines = [];
      
        try{
          throw new Error("throw a error to get the stack");
        }catch(objE){
          arrStackLines = objE.stack.split("\n");
        }
        let strLine = arrStackLines[arrStackLines.length -1];
        let intStart = strLine.indexOf("at ") + 3;
        let intEnd = strLine.indexOf("(<");
        Log.Message(strLine.substring(intStart, intEnd));
      }

       

      Btw. please add my vote..:-)

       

      Best regards 

       

      sign.png

        meinTest GmbH

        www.meinTest.software

       

       SmartBear preferred value-added Service

       Provider in the DACH region