1 Reply Latest reply on Mar 8, 2013 2:59 PM by Jhenderson

    Read and Write in a tag in PB using VBA




      I'm starting to program in ProcessBook using VBA. I want to make a basic program to read and write in a tag. The code I'm using is down below. If someone could help me on how to write in a tag I'll be very greatful. 



      Option Explicit
      Private Sub button1_Click()
          Dim vDate As Variant
          Dim vVal As Variant
          Dim lStatus As Long
          vVal = Value1.GetValue(vDate, lStatus)
          Text1.Contents = vVal
      End Sub




        • Re: Read and Write in a tag in PB using VBA

          Hi Aldo,


          According to the PI ProcessBook Programmer Reference Guide (located in ProcessBook under help), Text.Contents takes a string value. So you need to do a type conversion to the variant type in order for it to be valid.


          Try wrapping vVal on line 9 in a CStr type conversion so it looks like this:

          Text1.Contents = CStr(vVal)

          Here is my full code that I have tested to verify this works, if you are interested.

          Sub button_click()
              Dim vrDate As Variant
              Dim vrVal As Variant
              Dim vrStatus As Variant
              'Value1 is a value symbol displaying a SINUSOID tag's data
              vrVal = Value1.GetValue(vrDate, vrStatus)
              'We need to type convert the variant vrVal using CStr()
              'to properly store the value we received from Value1
              Text1.Contents = CStr(vrVal)
          End Sub

          Hope that helps,