Following on from my last post, Customising the Company Login window series – Visual Studio Tools revisited – Visual C#, where I completed the Customising the Company Login window customisation using Visual Studio and Visual C#, I wanted to create the same example using Visual Basic .Net.
Thanks to Tim Wappat from the Dynamic Coding Blocks blog for his post which helped me get past the issues I was having accessing the Continuum Integration Library:
Using the same approach as the Visual C# example, I repeating the process using Visual Basic .Net.
Below are the steps I used for Visual Basic .Net
- Ensure Visual Studio Tools for Microsoft Dynamics GP is installed. If necessary use Mariano’s article to get it installed on later versions of Visual Studio.
- Launch Visual Studio and create a new Microsoft Dynamics GP Addin Visual Basic project. I called mine SwitchCompanyWidthVB.
- In the Solution Explorer, right click on SwitchCompanyWidthVB project name and select Add >> Reference.
- In the Reference Manager window expand COM and search for “Continuum“.
- Select the version of the Dynamics Continuum Integration Library for your version of Microsoft Dynamics GP and click OK.
- In the Solution Explorer, right click on SwitchCompanyWidthVB project name and select Properties.
- Select References and click on Application.Dynamics. The properties will be displayed. Double click on Copy Local to change it to False.
- Repeat previous step for the Microsoft.Dexterity.Bridge reference.
- Using Tim’s idea to store the Dexterity sanScript code as a project resource, cut the script below to the clipboard. This is the same script as used in the Dexterity version of the customisation.
- In the Solution Explorer, right click on Resources and select Add >> New Item.
- In the Add New Item window, under General select Resources File.
- Change the Name of the resource from String1 to CompanySwitchScript.
- Paste in the Dexterity sanScript code from the clipboard into the Value cell.
- Replace the project code with the Visual Basic code below.
- The changes are:
- Registering the event when the Switch Company form opens.
- Handling the event by executing the previously stored Dexterity sanScript code.
- From the menus, select Build >> Build Solution.
- Copy the file “C:\Users\<Username>\Documents\Visual Studio 2013\Projects\SwitchCompanyWidthVB\SwitchCompanyWidthVB\bin\x86\Debug\SwitchCompanyWidthVB.dll” to your application’s Addins folder.
Visual Basic code
Imports System.Collections Imports System.Collections.Generic Imports Microsoft.Dexterity.Bridge Imports Microsoft.Dexterity.Applications Public Class GPAddIn Implements IDexterityAddIn ' IDexterityAddIn interface Sub Initialize() Implements IDexterityAddin.Initialize ' Register Event to trigger when Switch Company form opens AddHandler Microsoft.Dexterity.Applications.Dynamics.Forms.SwitchCompany.OpenAfterOriginal, AddressOf SwitchCompanyFormPre End Sub Sub SwitchCompanyFormPre(sender As Object, e As EventArgs) Dim CompilerApp As New Dynamics.Application Dim CompilerMessage As String = Nothing Dim CompilerError As Integer = 0 ' Execute SanScript in Dynamics GP CompilerError = CompilerApp.ExecuteSanscript(My.Resources.Resource1.CompanySwitchScript, CompilerMessage) If CompilerError <> 0 Then Windows.Forms.MessageBox.Show(CompilerMessage) End If End Sub End Class
Dexterity sanScript code
local integer l_adjust, h_pos, v_pos, h_size, v_size; default form to 'Switch Company'; default window to 'Switch Company'; l_adjust = 230; Field_GetPosition('(L) Company Names', h_pos, v_pos); Field_GetSize('(L) Company Names', h_size, v_size); move field '(L) Company Names' to h_pos - l_adjust, -1; resize field '(L) Company Names' to h_size + l_adjust, -1; move field '(L) RememberMe' to h_pos - l_adjust, -1; resize field '(L) RememberMe' to h_size + l_adjust, -1; move field '(L) SQL Server' to h_pos - l_adjust, -1; resize field '(L) SQL Server' to h_size + l_adjust, -1; move field 'User ID' to h_pos - l_adjust, -1; resize field 'User ID' to h_size + l_adjust, -1; move field '(L) Number of Users In' to h_pos - l_adjust, -1; {resize field '(L) Number of Users In' to h_size + l_adjust, -1; } move field 'Max Number User In System'[1] to h_pos - l_adjust, -1; {resize field 'Max Number User In System'[1] to h_size + l_adjust, -1; }
The end result is now the Switch company window has been modified via Visual Studio Tools.
Note: This code is a great example of using pass through Dexterity code from Visual Basic, however this technique is not supported by Microsoft.
Again, thanks to Tim Wappat for pointing me in the right direction.
David
This article was originally posted on http://www.winthropdc.com/blog.
4 thoughts on “Customising the Company Login window series – Visual Studio Tools revisited – Visual Basic .Net”