VBScript action with external function from pre-compiled DLL

If you wanted an action to do something that is not original provided by Foxtrot actions, what will you do? Well, I came across this challenge shared by a partner questioning if Foxtrot can call an external function provided by a dynamic link library file. The answer to me is obviously yes as you may use the advance actions such as C#, VB.NET, VBScript, etc. This is what i am going to share providing a step by step instruction on how I did that using the VBScript action of Foxtrot.

First thing first, I don’t think you should take any DLL and include it in your project without knowing the source, that would be too risky to do that. So we going to start building a simple dll for the testing purpose, and later to include this dll in our VBScript action call.

1. Create a C# Class Library project with your Visual Studio. I named my project FoxFunctions as captured in the screen below

2. For the exercise, we going to simple create a Class Library with just one public method “factorial”. This would be the function we going to call from our VBScript later to return factorial of a supplied number. The C# code that I have in my example as below using a recursion function to calculate the factorial of a number.

using System;
using System.Runtime.InteropServices;

namespace FoxFunctions
{
    [ComVisible(true)]
    public class Operations
    {
        [ComVisible(true)]
        public double factorial(int number)
        {
            if (number == 1)
                return 1;
            else
                return number * factorial(number - 1);
        }
    }
}

This is what it looks like in my Visual Studio project

3. Build the project, which gives us the FoxFunctions.dll and we will need to register the dll for the testing purpose, in my scenario i have the FoxFunctions.dll in my c:\ directory.

4. Create a new Botflow in Foxtrot to test the dll. We going to add the VBScript action as shown in the below capture.

5. Include the code below to include the FoxFunctions dll and test the factorial function.

6. With the “Run” option turned on, it should immediate run the action when we clicked “OK”. The MsgBox function will show the result of the myObj.factorial(4) as shown below.

7.  Here comes the question – “How can we get the exchange data between the VBScript code and Foxtrot?”. We going to add a variable for the exchange of data purpose.

8. We can leverage the FoxTrot Programming Action Functions – RPAEngine.SetVar to assign the returned value of the factorial function to the variableA that we created in the step earlier.

9. You should have noticed I have remarked the MsgBox in the above captured screen. When the action being executed, we will get the “Success” message, and the variableA value will be set to the result of myObj.factorial(4), which is 24 in this case as shown below.

With that, I hope you find my sharing helps or triggers more toughts when come to the need for adding additional functionalities you may need in your foxtroc botflow projects.