Forum Discussion

boaz_haim's avatar
boaz_haim
Contributor
13 years ago

How to use a function that is declared in its own unit?

Hi,

I have a script file named A and inside a function named A.

I want to use it in another script.



I found in the site several ways to do it but nothing seems to work

I had written in the beginning //USEUNIT A



and tried to call it by its name : A();



the I tried the  Runner["CallMethod"]("A")

 Runner["CallMethod"](A)



but nothing worked....

am I doing something wrong?

thanks



 

4 Replies

  • Hi Boaz hi,



    //USEUNIT A

    and in your script calling

    A();

    should work.



    Are both files in the same project ? If not, in the Project explorer panel, in the project where you want to use your file A, right click on "Script"   and select "Add existing item". Go to the folder where your file A is saved and validate.

    Remember that the file will be accessible from all project (original and all where you import) but will remain unique : modification from one place will be available everywhere.



    If both files are under the same project, I will suggest to try to not use the same name for function and file.



    Regards,

    Christophe

  • Hi Christophe,



    the files are in the same project.

    I tried to change the the function name to A_func.



    I still get the same error when trying to call the function:



    An exception occurred in the "B" unit at line 20: C#Script runtime error Object expectedAn exception occurred in the "A" unit at line 20:

    C#Script runtime error

    Object expected



    what can it be?
  • Hi Boaz hi,

    this message is not indicating that the function isnot recognized but that the function is not working as expected.

    could you share some code sample on

    - the function

    - the call to the function



    Best regards,

    Christophe
  • Hi,

    found the problam, thanks!



    I wrote USEUNIT A;



    small mistake  :)