Simple Write
Home Product
Details Free 
Demo Pricing &
Ordering Related
Products Support About Us

Please use our Code Center to obtain source-code and example projects/solutions:

http://codecenter.softwaretoolbox.com

 

Simple Write Example

The following example builds upon the Tutorial Using in VB6.

Within the "Form_Load()" event, place the following code:

Writing to a single Tag

   '
   'open a dialog to get a numeric value from the user

 Dim objWriteValue As Integer
   objWriteValue = InputBox("Enter value (integer) to write")
   '
   'create the opc web client object

 Dim objOPCWebClient As New EasyDA3
  '
   'now call the method to read a tag, specifying the
   'name of the OPC Server and the Tag...

   objOPCWebClient.WriteItemValue "", "OPCLabs.KitServer.2", _
         "Simulation.Register_I4", objWriteValue
  '
   'now display a value or an error...

   If Err.Number = 0 Then
       MsgBox "wrote ok"
   Else
       MsgBox "An error occurred: " & Err.Number
   End If

Writing to Multiple Tags

'define an opc web client object
Dim EasyDA As New EasyDA3

'define our variable to receive the values. it is a variant type
'that will be constructed by the opc web client within the read method
Dim Results

'now make the call to read multiple items
'you will see how all of the tags are being requested within the call itself
'you could break-up this instruction into separate lines, but I decided to
'do everything in one line
Results = EasyDA .WriteMultipleItemValues("", "OPCLabs.KitServer.2", _
  Array("Simulation.Register_I4", "Simulation.Register_R8", "Simulation.Register_BSTR"), _
  Array(23456, 2.3456789, "ABC"))

'now to define a string to use for building a message
Dim strWriteValue

'now to iterate thru the received collection
Dim I
For I = LBound(Results) To UBound(Results)

       'is this element within the collection an error-type?
       If VarType(Results(I)) <> 10 Then

           'no error, display the value of the tag
           strWriteValue = strWriteValue & "Element " & I & ": success"

       Else
           'errror found, so handle and display gracefully
           On Error Resume Next
           EasyDA.RaiseError Results(I)
           strWriteValue = strWriteValue & Err.Source & ": " & Err.Description _
               & " (0x" _
               & Hex(Err.Number
) & ")" & " **"
           On Error Goto 0
       End If

       'add a line-feed to the current message
       strWriteValue = strWriteValue & vbCrLf
Next

'display our message
Text1.Text = strWriteValue

Copyright Software Toolbox, Inc., 1996-2004, All Rights Reserved Worldwide.
148A East Charles Street, Matthews, North Carolina, USA 28105
Phone: 704-849-2773 or 1-888-665-3678 (US), Fax: 704-849-6388
sales@softwaretoolbox.com | support@softwaretoolbox.com