Referencing a Script from within a Script

You can create a script of often-used functions and re-use that script from any other scripts. You do this using the Add .NET Script Reference command.

Adding a script reference

  1. Create a single script that you want to re-use or reference from another script.
  2. Create a new driving script that will call your re-used script.
  3. Expand the Properties tab.
  4. Right click and select Add .NET Script Reference.
  5. Select the script that you want to use click OK.

Script example

The following sample contains a script file called Calculator that will be referenced from another script.

Note: Since the following has no Main() method, it cannot run on its own.
Public Class Calculator
  Public Shared Function Add(left As Integer, right As Integer)
		  Return left + right
	 End Function

  Public Shared Function Subtract(left As Integer, right As Integer)
		  Return left - right
	 End Function

  Public Shared Function Multiply(left As Integer, right As Integer)
    Return left * right
  End Function

  Public Shared Function Divide(left As Integer, right As Integer)
    Return left / right
  End Function
End Class

Create another script, and add Calculator as a reference (expand the Properties tab, right click, select Add .NET Script Reference, and select Calculator) , and use the following code:

Public Module Main
	Dim _desktop As Desktop = Agent.Desktop

	Public Sub Main()
		MsgBox("2 + 3 = " + Calculator.Add(2, 3).ToString())
	End Sub
End Module