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:
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 synchronization object, you do not have to worry about 'cross-thread exceptions when an event happens on a different thread from this one. WebSearch.Start(Me) 'Since you do not use events from Calc to modify the Windows form UI, you will not have cross-thread issues. Calc.Start() End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing If Calc.IsRunning Then Calc.Stop() End If If WebSearch.IsRunning Then WebSearch.Stop() End If End Sub Private Sub CalcStopped(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calc.Stopped 'If calculator is closed, close this application Application.Exit() End Sub '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 WebSearch.go.PerformClick() End If End Sub '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) WebLinkList.Items.Clear() For i As Int16 = 0 To WebSearch.Google.Links.Count – 1 WebLinkList.Items.Add(WebSearch.Google.Links.Item(i).Url()) Next End Sub End Class