Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

Robotic Automation example: An integration that uses VB.NET

Updated on September 10, 2021

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:

  1. In your VB.NET project, click Project > Add Reference.
  2. Add the following references:
    • OpenSpan
    • OpenSpan.Adapters
    • OpenSpan.Adapters.Web
    • OpenSpan.Adapters.Windows
  3. Click the Project References tab and add an adapter.
  4. 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 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
  • Previous topic Sample Robotic Automation solution: xmlDocumentComponent with schema
  • Next topic Robotic Automation example: Correcting the DataGridView Red X error

Tags

Robotics System Architect Robotic Process Automation

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us