VB6
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 Read Example

The following example builds upon the Tutorial Using in VB6.

Reading a Single Tag:

    Private Sub Form_Load()
    'define the webclient object
       Dim opcwebclient As New EasyDA3

       'define our object to receive the read
       Dim valueTimeQuality As VTQ3

       'read the tag
       Set valueTimeQuality = opcwebclient.ReadItem("", "OPCLabs.KitServer.2", "Simulation.Random")

       'now to check the status of the instruction
       If Err.Number = 0 Then

         'now to check the quality of the tag
         If valueTimeQuality.Quality >= 192 Then
           MsgBox valueTimeQuality.Value +
               & " (" & valueTimeQuality.Quality & ") " _
               & " @ " & valueTimeQuality.TimeStamp
         Else
             MsgBox "Quality not good: " _
                   & "quality: " & valuetimeQuality.Quality
         End If
       Else
         MsgBox "An error occurred: " & Err.Number
       End If
    End Sub

Reading Multiple Tags within a single transaction:

Private Sub Form_Load()

   'define our opcwebclient object
   Dim EasyDA As New EasyDA3

   'define our array of tags within the call to read them
   Dim Values
   Values = EasyDA.ReadMultipleItems("", " OPCLabs.KitServer.2", _
   Array("Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"))

   'now to check what was read by iterating thru the received collection
   Dim I
   For I = LBound(Values) To UBound(Values)

       'check if the data-type of the object in the collection is of type "error"
       If VarType(Values(I)) <> 10 Then

           'everything is ok
           Text1.Text = Text1.Text & "Element " & I & ": " & Values(I) & vbCrLf

       Else
           'an error has occured, so lets handle it
           On Error Resume Next
           EasyDA.RaiseError Values(I)

           'display a message indicating the error
           Text1.Text = Text1.Text & vbCrLf & "** " & Err.Source & ": " & Err.Description & " (0x" & Hex(Err.Number ) & ")" & " **"
           On Error Goto 0
       End If
   Next
End Sub

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