Robotic Automation 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 Robot Studio application adapters and use them by using .NET code.
This article assumes that you have the following expertise:
- 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 Robot Studio project. The VB.NET code is placed in a separate Microsoft 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.
The following code is an example:
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 synchronization 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