I had to make small changes to make your code work (move creation of "a" before the main If loop and also add "Else" to the Invert loop):
Dim a As New SubscriptionHandlerEventArgs '* Move these 2 lines before the "If" statement
a.SubscriptionDetail = Subscript '*
If (e.PlcAddress Is Nothing) OrElse (String.Compare(address, e.PlcAddress, True) = 0) Then
If e.ErrorId = 0 Then
If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
'* Check if the value should be inverted
If Subscript.Invert Then
'* Try to invert a boolean value
Try
Dim ea As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs
'* Clone the EventArgs for the inversion because there may be another subscription that doesn't need inverted
ea = CType(e.Clone, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
Dim x As New System.Collections.ObjectModel.Collection(Of String)
Dim s As String = (Convert.ToString(Not CBool(e.Values(0))))
x.Add(s)
ea.Values = x
a.PLCComEventArgs = ea
Catch ex As Exception
Dim dbg = 0
End Try
Else
a.PLCComEventArgs = e '* Include the "Else" along with this line since NullException was being thrown
End If
Else
'* No data returned from driver
e.ErrorId = -999
e.ErrorMessage = "No Values Returned from Driver"
End If
If Subscript.CallBack IsNot Nothing Then
Subscript.CallBack.Invoke(sender, a)
End If
'********************************************
'* Process the AutoProperty subscribed items
'********************************************
If Me.Parent IsNot Nothing And a.SubscriptionDetail.PropertyNameToSet IsNot Nothing AndAlso (String.Compare(a.SubscriptionDetail.PropertyNameToSet, "") <> 0) Then
If e.ErrorId = 0 Then
Try
'* Does this property exist?
If m_Parent.GetType().GetProperty(a.SubscriptionDetail.PropertyNameToSet) IsNot Nothing Then
'* Write the value to the property that came from the end of the PLCAddress... property name
m_Parent.GetType().GetProperty(a.SubscriptionDetail.PropertyNameToSet). _
SetValue(m_Parent, Utilities.DynamicConverter(a.PLCComEventArgs.Values(0), m_Parent.GetType().GetProperty(a.SubscriptionDetail.PropertyNameToSet).PropertyType), Nothing)
End If
Catch ex As Exception
OnDisplayError("INVALID VALUE RETURNED!" & a.PLCComEventArgs.Values(0))
End Try
Else
OnDisplayError("Com Error " & a.PLCComEventArgs.ErrorId & "." & a.PLCComEventArgs.ErrorMessage)
End If
End If