Customising the Company Login window series – Visual Studio Tools revisited – Visual Basic .Net


David Meego - Click for blog homepageFollowing 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

  1. 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.
  2. Launch Visual Studio and create a new Microsoft Dynamics GP Addin Visual Basic project. I called mine SwitchCompanyWidthVB.
  3. In the Solution Explorer, right click on SwitchCompanyWidthVB project name and select Add >> Reference.
  4. In the Reference Manager window expand COM and search for “Continuum“.
  5. Select the version of the Dynamics Continuum Integration Library for your version of Microsoft Dynamics GP and click OK.
  6. In the Solution Explorer, right click on SwitchCompanyWidthVB project name and select Properties.
  7. Select References and click on Application.Dynamics. The properties will be displayed. Double click on Copy Local to change it to False.
  8. Repeat previous step for the Microsoft.Dexterity.Bridge reference.
  9. 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.
  10. In the Solution Explorer, right click on Resources and select Add >> New Item.
  11. In the Add New Item window, under General select Resources File.
  12. Change the Name of the resource from String1 to CompanySwitchScript.
  13. Paste in the Dexterity sanScript code from the clipboard into the Value cell.
  14. Replace the project code with the Visual Basic code below.
  15. The changes are:
    1. Registering the event when the Switch Company form opens.
    2. Handling the event by executing the previously stored Dexterity sanScript code.
  16. From the menus, select Build >> Build Solution.
  17. 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 &lt;&gt; 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.

SwitchCompanyWidth

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

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s