Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

 Overview

This document describes the procedures and utilities for building real time Web based graphic screens under Visual Basic .NET 2003.  These screens may be animated using real time data from a control system.  Screens may be displayed on any workstation using a browser such as Microsoft Internet Explorer 5.5.

Upgrade TPRI VB6 Screens to VB.NET

 Starting VB.NET Development
  1. Click Start

  2. Select Programs

  3. Select Microsoft Visual Studio .NET 2003

  4. Click Microsoft Visual Studio .NET 2003 to start .NET 2003 development environment

 Upgrade existing VB6 project using Microsoft Upgrade Tools

Microsoft Upgrade Tools will handle about 80% of the conversion (depending on the project). But unfortunately the rest of the work has to be done manually.

Before attempting upgrade, make sure the vb6 project can be opened on your system.  This will ensure you have the correct controls installed and the module paths correct.

  1. Within .NET 2003 development environment click Open Project button

  2. Select a VB6 project (vbp file)

  3. Welcome to Visual Basic Upgrade Wizard window will open, Click Next

  4. Choose a project Type: ensure that “DLL/custom control library” is selected, Click Next

  5. Select the new VB.NET project directory name and location

  6. Folder does not exist, create it? Click Yes, then click Next to begin

  7. If you receive an Upgrade Failed error, it is because referenced modules from the VB6 project cannot be found in the specified location.  Copy the modules folder to the correct location and repeat from step 2

 Clean up Directory and Correct Name of Files

Any controls in the original VB6 project that are not Microsoft standard controls will not be converted to the corresponding new .NET assemblies (The upgrade tools have no way of knowing there is any new .NET assembly for a given COM component). Instead the upgrade tools will treat the control just as there is no corresponding .NET assembly. It will create the interop/Ax* wrappers for the control (COM). Since all the TPRI standard controls are converted to .NET there is no need to keep any of the interop/Ax files around anymore.

Most of the common modules are included in the TPRI.BaseControl or TPRI.BaseScreen. But there are situations that some of the screens have their own special module(s). In that case the module(s) should remain in the project.

The .NET version of IobjSafe is implemented in the section: Signing of TPRI Screens.

The option of using Namespace to group the assemblies will also change the way we name the solutions, projects and classes.

  1. In windows explorer, browse to newly created project directory

  2. Delete the directory _UpgradeReport_Files

  3. Delete the files:
    _UpgradeReport.htm
    ErrRpt.vb
    IobjSafe.vb
    Modules.vb
    Any Interop/Ax*.dll file
    Any Interop/Ax*.vb file

  4. Back in the solution explorer of the .NET design environment:

  5. Change the file names accordingly:
    solution name
    project name
    .vb name

  6. Delete the files:

    _UpgradeReport.htm
    ErrRpt.vb
    IobjSafe.vb
    Modules.vb
    Any Interop/Ax*.dll file
    Any Interop/Ax*.vb file

  7. Save all files

 References

For the same reason stated above there is no need to keep any of the interop/Ax or IObjectSafety reference anymore. It is also important to remove any COM object reference. Replace the COM components with the corresponding .NET assemblies.

  1. Expand the References folder

The interop files are shown as just tpri*. You can show their full names by selecting them and looking at the properties for that file.

2. Replace any reference to Interop/Axtpri* with corresponding tpri .NET control

  • Easiest way is to add all references first:
    Right-click References, select Add Reference
    Browse to the Bin directory which contains the tpri control dlls and select the corresponding TPRI.* file
    Continue to browse to add the rest of the tpri controls
    Be sure to add the TPRI.BaseScreen and TPRI.BaseControl references

3. If you receive an error concerning changing where the array references are found, click OK

4. Remove the references:

  • IObjectSafetyTLB
    VBRUN
    Std*
    MSDATASRC
    Any AxucxxxxxArray

5. Add any other necessary .NET reference

  • TPRI.xxxx
    TPRI.shape is needed when TPRI.ActiveShape is used
    Gigasoft.ProEssentials.dll
    C1.win.c1flexgrid.dll
    C1.Common.dll

 Project Settings and Attributes

'Statement Option Explicit On' forces explicit declaration of all the variables in the module. (The default: Option Explicit On)

VB6 is not a type-safe language. VB.Net is type-safe (like C). 'Statement Option Strict On' enforces strict type checking. (The default: Option Strict Off)

  1. View Code of ProjectName.vb

  2. At the top, set the Options:
    Option Explicit On
    Option Strict On

  3. On the following line, Remove the control class attribute: <System.Runtime.InteropServices.ProgId("ucxxxx_NET.ucxxxx")>

  4. Change the Public Class name to match the project name

 Remove/Change Code

The TPRI.BaseScreen includes most of the shared code including sub StartFromAsp, Link, events GotoUrl and ErrorTerminate. It also includes the code to run TSentry screens under Web Browser. All Tsentry screens are built on top of TPRI.BaseScreen that means to inherit TPRI.BaseScreen instead of System.Windows.Forms.UserControl.

Microsoft Upgrade Tools create an argument class for each of the VB6 events that have any argument. The argument class approach is Microsoft .NET's standard way of passing all parameters as one argument. Here we choose to use the way we all are familiar with (each parameter as a separate argument).

  1. Change the line: Inherits System.Windows.Forms.UserControl to Inherits TPRI.BaseScreen

  2. Remove IobjectSafety related code:
    Delete the line: Implements IObjectSafetyTLB.IobjectSafety
    Delete the two sub routines

  3. Remove URL related code (ex):
    GoToURLEventArgs class
    Link sub routine

  4. Remove Events (ex):
    GotoUrl
    ErrorTerminate

 Replace TPRI Standard Controls

By modifying the code in the region, the Windows Form Designer-generated code will allow us to retain most of the properties of the original controls including, most importantly, location and size of the controls. Most of the property settings will not be affected. But some of the property settings need to be manually corrected because of the name change, type change or even add/removal.

  1. Expand Region: Windows Form Designer generated code

  2. In the declaration section (noted by 'Required by the Windows Form Designer’), replace any Interop/Ax controls with TPRI controls.  The easiest way is with a find/replace (since there are hundreds).

  3. Ignore the Ax*Array errors for now.

  4. Correct the property name and value if necessary. (Some of the TPRI control properties are changed.)

 Name VB.NET User Screen (.NET Assembly)

Modules and classes live in namespaces. All the classes defined in the standard Tsentry controls and screens are grouped under namespace TPRI. You are encouraged to use your own namespace for a set of local screens.

  • Use Namespace <namespace> (for example: TPRI)

  • Name class name as original class name <class> without the prefix (tpri)

  • Make sure to close design view if it is open

  1. Right click project node in the Solution Explorer and select Properties

  2. Select Common Properties | General

  3. Enter Assembly name as: <namespace>.<class>

  4. Enter Root namespace as: <namespace>

  5. Click OK button

  6. Save changes for the project

 Control Array

Control array in VB6 as we know does not exist anymore in VB.NET. Microsoft Upgrade Tools will create an array for each of the VB6 standard control array using the functionalities in Microsoft.VisualBasic.Compatibility.dll. Tsentry includes the customized control array classes for some of the TPRI standard controls (ActiveShapeArray, CmdButtonArray…).

  1. For Microsoft WinForm controls there is an option to create control array using Microsoft.VisualBasic.Compatibility class. Microsoft upgrade tool will convert the existing VB6 control arrays.

  • Reference Microsoft.VisualBasic.Compatibility.dll

  • Friend WithEvents labels As Microsoft.VisualBasic.Compatibility.VB6.LabelArray

2. For the Tsentry standard controls use the included control array classes (ActiveShapeArray, CmdButtonArray…).

For other type of controls (user control), it is necessary to create a customized ArrayList class.

Create a customized ArrayList class

This code should be located before the ‘Region: Windows Form Designer generated code’

There needs to be a class for each different type of array listed (e.g. ActiveShape and CmdButton)

Private Class xxxxList
Inherits ArrayList

Public Overrides Function Add(ByVal Obj As Object) As Integer
If Obj.GetType Is GetType(xxxx) Then
Return MyBase.Add(Obj)
Else
Return -1
End If
End Function
End Class

Declare a variable

This code goes in the declarations section (generally found below the Region)

The easiest way is to cut the array variable code from the ‘Friend With Events’ section and paste it into the declarations section.  Then use Find/Replace from there.

Private mcolxxxx As xxxxList
    OR 
Private WithEvents mcolxxxx As xxxxList

Add the controls to the list

This is located at the top inside the Region. The easiest way to do this is to copy the private declarations just added so you can see the arrays that need to be declared.

Public Sub New()
                  MyBase.New()
                  'This call is required by the Windows Form Designer.
                  InitializeComponent()

                  mcolxxxx = New xxxxList
         mcolxxxx.Add(xxxx_0)
mcolxxxx.Add(xxxx_1)
…
End Sub

Use the ArrayList as a zero based array: MessageBox.Show(Mcolxxxx(0).Name)

Some of the control array classes have event(s). The events work the similar way as the control array events in VB6. Each control in the array is identified by index.

 Remove Error-Causing Code

Remove any COM component related code within region: Windows Form Designer generated code

  1. Remove the lines with:
    OcxState errors
    SetIndex errors

  2. Rename any references from original project name to updated name.

  3. Delete all the lines beginning with 'Ctype(Me.*' and ending with either 'BeginInit()' or 'EndInit()'.

  4. Delete array error code from the Me. section

 UserControl_Initialize

UserControl_Initialize() is not a function in .NET user control class anymore. Microsoft Upgrade Tools will keep the original UserControl_Initialize() as a private subroutine and call it from function New() in region: Windows Form Designer generated code. You have a choice here to keep the way it is, or simply change the name of the function or move the code from Windows Form UserControl_Initialize() to function New() in region: Windows Form Designer generated code.

For some cases it may be better to move the code into class Load event.

  1. Right-click on UserControl_Initialize() at the top of the Region in the Public Sub New and select Go To Definition. 

  2. Cut the Private Sub UserControl_Initialize() code and paste over the UserControl_Initialize() line (removing the subroutine, but keeping the inside code)

 TPRI Base Screen

TPRI.BaseScreen includes most of the shared code, including sub StartFromAsp, Link, events GotoUrl and ErrorTerminate. It also includes the code to run Tsentry screens under Web Browser.

  • All Tsentry screens are built on top of TPRI.BaseScreen. This means that they inherit the attributes of  TPRI.BaseScreen instead of the System.Windows.Forms.UserControl.

  • All TPRI screens inherit TPRI.BaseScreen.

  • TPRI screens may override some of the interfaces of TPRI.BaseScreen depending on the requirement.

  • TPRI.BaseScreen provides the following public functions:

StartFromAsp
(
ByRef vobjWindow As Object
) 
As Integer

Public Overridable Sub Link
(
ByVal URL As String
)
  • TPRI.BaseScreen provides some protected overridable functions. These overriding functions are only needed when an additional function other than OPCStartComm, DataDict, or TrendCom is called in the StartComm public function.

  • The Startcomm function can be deleted.

  • Below are the overridable functions.

Protected Overridable Function StartScreen
(
ByRef vobjWindow As Object
) 
As Integer

Protected Overridable Sub SecureScreen
(
ByVal securityLevel As Integer
)

TPRI.BaseScreen provides all the functions, variables and constants within the following modules:
ReadWriteCookie
SecurityDef

A timer is used to execute security encryption functionalities.

Handle events for the .NET assembly hosted on a HTML page

  • Add GuidAttribute to the screen interface

  • Add InterfaceTypeAttribute to indicate that the interface is an Idispatch interface

  • Add DisIdAttribute to any members in the source interface to specify the COM DISPID

  • Add a ComSourceInterfaceAttribute to the control to identify the list of interfaces that are exposed as COM event source

  • Imports System.ComponentModel

  • Imports System.Runtime.InteropServices

  • Declare public events

  • Raise events in code

 Allow Partially-Trusted Caller (Internet Explorer)

The Microsoft .NET Framework requires that you explicitly enable strong-names assemblies that partially-trusted callers such as Internet Explorer use.  You must now declare the custom attribute <Assembly: System.Security.AllowPartiallyTrustedCallers()> class for the strong-named assemblies that are designed for use by partially-trusted code. Without this explicit declaration, the caller must have full trust permission to use the code.

  1. Open AssemblyInfo.vb for editing from solution explorer

  2. Add Imports System.Security

  3. Add <Assembly: AllowPartiallyTrustedCallers()>

 Version

Version of the assembly (dll here).

  1. Open AssemblyInfo.vb for editing

  2. Add <Assembly: AssemblyVersion(“#.#.#.#”)> (If not already present)

 Signing TPRI Screens

An assembly that has a public key and digital signature is said to have a strong name. In order to build an assembly with a strong name, you must first acquire a pair of keys. One is a public key whose value will be written into the physical image of assembly files. The other is a private key that is used to generate digital signatures. The process of using the private key in order to write a digital signature to the image of an assembly file is known as signing.

  1. Create private/public key file <corp name>.snk using sn.exe

  2. Copy <corp name>.snk file to the project directory (optional)

  3. Open AssemblyInfo.vb for editing

  4. Add <Assembly: AssemblyKeyFile(“..\..\<corp name>.snk”)> to file AssemblyInfo.vb

 Misc. Fixes
  1. Change:

    Private Sub tpriOpcMgr1_opcOnRestart(ByVal eventSender As System.Object,
    ByVal eventArgs As System.EventArgs) Handles tpriOpcMgr1.opcOnRestart
    To

    Private Sub tpriOpcMgr1_OnRestart(ByVal Sender As Object) Handles tpriOpcMgr1.OnRestart

  2. Change:

    tpriOpcMgr1.opcAutoAddItem to tpriOpcMgr1.AutoAddItem

  3. Change:
    Private Sub tpriOpcMgr1_opcDataUpdate(ByVal eventSender As System.Object, ByVal eventArgs As AxtpriOpcMgr.__ucTpriOpcMgr_opcDataUpdateEvent) Handles tpriOpcMgr1.opcDataUpdate
    To
    Private Sub tpriOpcMgr1_OnDataUpdate(ByVal Sender As Object, ByVal tag As String, ByVal value As Object, ByVal timestamp As Date, ByVal quality As Integer) Handles tpriOpcMgr1.OnDataUpdate

  4. With 'tag' is not a member of 'System.EventArgs' Error. Use “tag” instead of “eventArgs.tag”

  5. Change:
    tpriOpcMgr1.opcWriteItem to tpriOpcMgr1.WriteItem

  6. 'The statement 'Option Strict On' disallows late binding. This error happens most often with array variables. To fix the error, change the function call for .NET to cast variable, for example:
    tcbEnableMotor(i).CtlEnabled
    To
    CType(tcbEnableMotor(i), TPRI.CmdButton).Enabled

  7. Error associated with event. This often occurs because a vb6 control property is no longer used in .NET.

    To fix it, comment out the subroutine (event sub). Select the control from the top left dropdown and then select the event (Ex: Click instead of ClickEvent) from the top right dropdown. This step will generate the correct event sub to use in its place.

 Control Properties Upgrade
  1. The majority of tpri/Gigasoft/VSFlex control properties are not saved through the conversion process.

  2. The tDataSource property is not transferred through the entire conversion process

  3. tpri.activeshape often have many properties associated with them and frequently setup on the screen as arrays. 

  4. To save time instead of updating the properties for each individual control, if two or more activeshape controls have the same properties, you can copy the properties through: <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() section.  Denoted by me.tasControlName.ActiveShapeSetup = xxxxxxx which can be copied to another activeshape.

  5. For property conversion of Gigasoft and VSFlex controls, refer to separate conversion documents.

 Other Common Upgrade Problems
  1. Variant

    1. Replace with object when array data type is involved
      Replace with string when both numeric and non-numeric data types are involved

  2. Color type
    > System.Drawing.Color
    > System.Drawing.SystemColor

  3. Windows API Any Type
    > Specify the data type
    > Overload the function if necessary

  4. Shape Control
    > Use TPRI.Shape control instead

  5. Line Control
    > Draw a line in code:
     Imports System.Drawing
     Imports System.Drawing.Drawing2D

    > Dim lobjGraphics as Graphics
     LobjGraphics.DrawLine(Pens.Red, X1, Y1, X2, Y2)
     LobjGraphics.Dispose()

  6. File and Directory
    > Use .NET File class
     Imports System.IO
     Dim lobjFile As File
     lobjFile.Copy(SourceName, DestinationName, True)
     lobjFile.Delete(SourceName)

    > Use .NET Directory class
     Imports System.IO
     Directory.Exists(Name)
     Directory.CreateDirectory(Name)

  • No labels