Jump to content

VB .Net error


Recommended Posts


I need to write to a timer preset and am getting an 'object' error using the .net driver.

I'm sort of between a rock and a hard place...

THanks in advance.

Below is the 'function' that attempts to write -

Public Function Write_TimerPreset(ByVal tmrIndex As Int16, ByVal TmrValue As integer) As Boolean

Dim values As Object() = New Object(2) {}


values(0) = DirectCast(TmrValue, Object)



MessageBox.Show("One of more of the values are not valid")

Return False

Exit Function

End Try

Dim wo As WriteOperands = New WriteOperands()

With wo

.NumberOfOperands = 1

.OperandType =


.StartAddress = tmrIndex

.Values = values

.TimerValueFormat = TimerValueFormat.SecondsFormat

End With

Dim rw(0) As ReadWriteRequest

rw(0) = wo




Dim ErrorMessage As String = "Could not communicate with the PLC" & vbCrLf & "Error # " & Str(Err.Number) & " was generated by " _

& Err.Source & vbCrLf & Err.Description

'Display the message as a critical message.


MsgBoxStyle.Critical, "PLC Connection Error")


"Unitronics Class", "Write_TimerPreset", Str(Err.Number), Err.Source, Err.Description, Now(), EmployeePK, 0)

Return False

End Try

Return True

End Function


Link to comment
Share on other sites

That's because you have a 3 values array and only the first one has a value (while the other 2 are Null, ergo Null Reference exception), and you are also writing only 1 value so no need to 3 values array.

instead of:

Dim values As Object() = New Object(2) {}

have it:

Dim values As Object() = New Object(0) {}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...