Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

titleOverview

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

Expand
titleStarting 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

...

Expand
titleControl 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…).

Info

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)

Code Block
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.

Code Block
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.

Code Block
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.

Expand
titleRemove 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

Expand
titleUserControl_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)

Expand
titleTPRI 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:

Code Block
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.

Code Block
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

Info

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

Expand
titleAllow 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()>

Expand
titleVersion

Version of the assembly (dll here).

  1. Open AssemblyInfo.vb for editing

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

Expand
titleSigning 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

Expand
titleMisc. 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.

Expand
titleControl 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.

Expand
titleOther 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)