Example: An integration that uses VB.NET
This article describes how to integrate a Windows application (calculator) and a web application (the Google search page) by using VB.NET code. It also demonstrates how to start Pega® Robotic Automation Studio application adapters and use them by using .NET code.
This article assumes that you:
- Are familiar with Visual Studio and VB.NET
- Know how to create adapters and interrogate controls
Integrating applications requires the use of adapters, which are essentially classes that describe and work with the application that is being integrated. The adapters in this case are placed in a single Robotic Automation Studio project. The VB.NET code is placed in a separate Visual Studio project that is part of the same solution.
You must add references to your VB.NET project before it recognizes the adapters. You can do this in a couple of ways, the easiest of which is to complete the following steps:
- In your VB.NET project, click Project > Add Reference.
- Add the following references:
- Click the Project References tab and add an adapter.
- Rebuild the solution.
This is important because when you start using the adapter and controls in the .NET project, you need a project reference that includes those objects. When you add a project reference from the OpenSpanIntegration project to the VB_Calc_Sample project, the.NET code recognizes any controls that are interrogated.
If you add or remove controls or adapters, always rebuild the project so that the references are also added or removed for any other projects that use them.
The following code is an example:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Calc = New OpenSpanIntegration.Calculator
WebSearch = New OpenSpanIntegration.WebSearch
'Handler for pressing the M+ key on calc
AddHandler Calc.btnMPlus.Click, AddressOf CalcMPlusPressed
'Handler for when the web page changes
AddHandler WebSearch.Search_Results.Created, AddressOf SearchResultsCreated
'By using the form (Me) as a sychronization object, you do not have to worry about
'cross-thread exceptions when an event happens on a different thread from this one.
'Since you do not use events from Calc to modify the Windows form UI, you will not have cross-thread issues.
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If Calc.IsRunning Then
If WebSearch.IsRunning Then
Private Sub CalcStopped(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calc.Stopped
'If calculator is closed, close this application
'When the Calculator M+ key is pressed, do a web search if the web query page can be found
Private Sub CalcMPlusPressed(ByVal sender As System.Object, ByVal e As System.EventArgs)
If WebSearch.query.IsCreated Then
WebSearch.query.Text = Calc.txtTextBox.Text
'Displays all the links found on the search page after it loads
Private Sub SearchResultsCreated(ByVal sender As System.Object, ByVal e As System.EventArgs)
For i As Int16 = 0 To WebSearch.Google.Links.Count – 1
Published December 6, 2016 — Updated March 1, 2018