F
<p>I'm having trouble making the transition from VB6 to VB.NET. I have a VB6 application which reads some data using the OPCDaAuto.DLL (OPC Automation 2.0) and then places it in a database. I'm trying to convert the code to VB.NET (for my own education). Here are the first few lines of VB6 code... I have a reference to OPCDaAuto.DLL (OPC Automation 2.0)
<pre>
Option Explicit
Dim OPCSvr As New OPCAutomation.OPCServer
Dim OPCSvrGroups As OPCAutomation.OPCGroups
Private Sub Command1_Click()
OPCSvr.Connect ("OPCDataCtrl.OPCSimServer.1")
Set OPCSvrGroups = OPCSvr.OPCGroups
OPCSvrGroups.DefaultGroupIsActive = True
End Sub
</pre>
<p>Here's the same VB.NET code generated by the upgrade wizard...
<pre>
Dim OPCSvr As New OPCAutomation.OPCServer
Dim OPCSvrGroups As OPCAutomation.OPCGroups
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
OPCSvr.Connect("OPCDataCtrl.OPCSimServer.1")
OPCSvrGroups = OPCSvr.OPCGroups
OPCSvrGroups.DefaultGroupIsActive = True
End Sub
</pre>
<p>When I run the VB.NET version I recieve the following error on the line... "OPCSvrGroups.DefaultGroupIsActive = True"
*******
An unhandled exception of type 'System.NullReferenceException' occurred in Project1.exe
Additional information: Object reference not set to an instance of an object.
*******
<p>I don't understand why, I set OPCSvrGroups = OPCSvr.OPCGroups, what is the problem here?
<pre>
Option Explicit
Dim OPCSvr As New OPCAutomation.OPCServer
Dim OPCSvrGroups As OPCAutomation.OPCGroups
Private Sub Command1_Click()
OPCSvr.Connect ("OPCDataCtrl.OPCSimServer.1")
Set OPCSvrGroups = OPCSvr.OPCGroups
OPCSvrGroups.DefaultGroupIsActive = True
End Sub
</pre>
<p>Here's the same VB.NET code generated by the upgrade wizard...
<pre>
Dim OPCSvr As New OPCAutomation.OPCServer
Dim OPCSvrGroups As OPCAutomation.OPCGroups
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
OPCSvr.Connect("OPCDataCtrl.OPCSimServer.1")
OPCSvrGroups = OPCSvr.OPCGroups
OPCSvrGroups.DefaultGroupIsActive = True
End Sub
</pre>
<p>When I run the VB.NET version I recieve the following error on the line... "OPCSvrGroups.DefaultGroupIsActive = True"
*******
An unhandled exception of type 'System.NullReferenceException' occurred in Project1.exe
Additional information: Object reference not set to an instance of an object.
*******
<p>I don't understand why, I set OPCSvrGroups = OPCSvr.OPCGroups, what is the problem here?