VBScript action with external function from pre-compiled DLL

  • 21 July 2019
  • 0 replies
  • 231 views

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

3229i3FD56FB29A39FB72.png

 

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 project3235i8897BCF1DE73AB71.png

 

 

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.

3232i97F5F745E37CF0F5.png

 

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

 

 

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

 

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.3237iB91913DC8FF39CC1.png

 

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.3238iAB87AA6598EF3287.png

 

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.3239i1D87C0DC97CEEB41.png

 

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.3240i8C22B2AF8F478C7E.png

 

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.


0 replies

Be the first to reply!

Reply