- Created by Luke Cerwin , last modified on Jun 29, 2022
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 8 Next »
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
Click Start
Select Programs
Select Microsoft Visual Studio .NET 2003
Click Microsoft Visual Studio .NET 2003 to start .NET 2003 development environment
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.
Within .NET 2003 development environment click Open Project button
Select a VB6 project (vbp file)
Welcome to Visual Basic Upgrade Wizard window will open, Click Next
Choose a project Type: ensure that “DLL/custom control library” is selected, Click Next
Select the new VB.NET project directory name and location
Folder does not exist, create it? Click Yes, then click Next to begin
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
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.
In windows explorer, browse to newly created project directory
Delete the directory _UpgradeReport_Files
Delete the files:
_UpgradeReport.htm
ErrRpt.vb
IobjSafe.vb
Modules.vb
Any Interop/Ax*.dll file
Any Interop/Ax*.vb fileBack in the solution explorer of the .NET design environment:
Change the file names accordingly:
solution name
project name
.vb nameDelete the files:
_UpgradeReport.htm
ErrRpt.vb
IobjSafe.vb
Modules.vb
Any Interop/Ax*.dll file
Any Interop/Ax*.vb fileSave all files
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.
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
…
'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)
View Code of ProjectName.vb
At the top, set the Options:
Option Explicit On
Option Strict OnOn the following line, Remove the control class attribute: <System.Runtime.InteropServices.ProgId("ucxxxx_NET.ucxxxx")>
Change the Public Class name to match the project name
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).
Change the line: Inherits System.Windows.Forms.UserControl to Inherits TPRI.BaseScreen
Remove IobjectSafety related code:
Delete the line: Implements IObjectSafetyTLB.IobjectSafety
Delete the two sub routinesRemove URL related code (ex):
GoToURLEventArgs class
Link sub routineRemove Events (ex):
GotoUrl
ErrorTerminate
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.
Expand Region: Windows Form Designer generated code
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).
Ignore the Ax*Array errors for now.
Correct the property name and value if necessary. (Some of the TPRI control properties are changed.)
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
Right click project node in the Solution Explorer and select Properties
Select Common Properties | General
Enter Assembly name as: <namespace>.<class>
Enter Root namespace as: <namespace>
Click OK button
Save changes for the project
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…).
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 any COM component related code within region: Windows Form Designer generated code
Remove the lines with:
OcxState errors
SetIndex errorsRename any references from original project name to updated name.
Delete all the lines beginning with 'Ctype(Me.*' and ending with either '
BeginInit()
' or 'EndInit()
'.Delete array error code from the Me. section
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.
Right-click on UserControl_Initialize() at the top of the Region in the Public Sub New and select Go To Definition.
Cut the Private Sub UserControl_Initialize() code and paste over the UserControl_Initialize() line (removing the subroutine, but keeping the inside code)
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
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.
Open AssemblyInfo.vb for editing from solution explorer
Add Imports System.Security
Add <Assembly: AllowPartiallyTrustedCallers()>
Version of the assembly (dll here).
Open AssemblyInfo.vb for editing
Add <Assembly: AssemblyVersion(“#.#.#.#”)> (If not already present)
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.
Create private/public key file <corp name>.snk using sn.exe
Copy <corp name>.snk file to the project directory (optional)
Open AssemblyInfo.vb for editing
Add <Assembly: AssemblyKeyFile(“..\..\<corp name>.snk”)> to file AssemblyInfo.vb
Change:
Private Sub tpriOpcMgr1_opcOnRestart(ByVal eventSender As System.Object,
ByVal eventArgs As System.EventArgs) Handles tpriOpcMgr1.opcOnRestart
ToPrivate Sub tpriOpcMgr1_OnRestart(ByVal Sender As Object) Handles tpriOpcMgr1.OnRestart
Change:
tpriOpcMgr1.opcAutoAddItem
totpriOpcMgr1.AutoAddItem
Change:
Private Sub tpriOpcMgr1_opcDataUpdate(ByVal eventSender As System.Object, ByVal eventArgs As AxtpriOpcMgr.__ucTpriOpcMgr_opcDataUpdateEvent) Handles tpriOpcMgr1.opcDataUpdate
ToPrivate 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
With 'tag' is not a member of 'System.EventArgs' Error. Use “tag” instead of “eventArgs.tag”
Change:
tpriOpcMgr1.opcWriteItem
totpriOpcMgr1.WriteItem
'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
ToCType(tcbEnableMotor(i), TPRI.CmdButton).Enabled
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.
The majority of tpri/Gigasoft/VSFlex control properties are not saved through the conversion process.
The tDataSource property is not transferred through the entire conversion process
tpri.activeshape often have many properties associated with them and frequently setup on the screen as arrays.
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.
For property conversion of Gigasoft and VSFlex controls, refer to separate conversion documents.
Variant
Replace with object when array data type is involved
Replace with string when both numeric and non-numeric data types are involved
Color type
> System.Drawing.Color
> System.Drawing.SystemColorWindows API Any Type
> Specify the data type
> Overload the function if necessaryShape Control
> Use TPRI.Shape control insteadLine 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()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