1 Reply Latest reply on Oct 27, 2014 2:36 PM by Gregor

    Dataset & Changing photo based on the dataset value in Processbook

    thomas.clchan

      Hi,

       

      Although Processbook contains the multi-state label, it doesn't allow us to change the photo based on the tag value/dataset value.

       

      For our case, we have created the dataset and we want to change the photo based on the dataset value. I asked techsupport that it doesn't have default functionalities to accomplish this but have to use VBA.

       

      Can you provide few line of codes to accompish this?

       

      Thanks in advance.

       

      Thomas

       

       

       

       

       

       

       

       

        • Re: Dataset & Changing photo based on the dataset value in Processbook

          Hello Thomas,

           

          Please find attached Example for your reference.

           

          Based on the status reported by default PI Point CDM158, a different Image is loaded into a Microsoft Forms 2.0 Frame. Please note that the VBA project requires a reference to PI SDK library. Please let me know if any part of the code requires explanation.

           

           

           
          Dim sImage As String
          Dim displayPath As String
          Dim srv As Server
          Dim myPoint As PIPoint
          
          Private Sub Display_Open()
              Init
          End Sub
          
          Private Sub Init()
              displayPath = ThisDisplay.Path
              Do While Right(displayPath, 1) <> "\"
                  displayPath = Left(displayPath, Len(displayPath) - 1)
              Loop
              Set srv = Servers.DefaultServer
              Set myPoint = srv.PIPoints.Item("CDM158")
          End Sub
          
          Private Sub Display_DataUpdate()
              Dim myValue As PIValue
              Dim sValue As String
              If myPoint Is Nothing Then Init
              Set myValue = myPoint.Data.Snapshot
              sValue = myValue.Value
              Select Case sValue
                  Case "Manual"
                      sImage = displayPath & "PI00.jpg"
                  Case "Auto"
                      sImage = displayPath & "PI01.jpg"
                  Case "Cascade"
                      sImage = displayPath & "PI02.jpg"
                  Case "Program"
                      sImage = displayPath & "PI03.jpg"
                  Case "Prog-Auto"
                      sImage = displayPath & "PI04.jpg"
              End Select
              Frame1.Picture = LoadPicture(sImage)
          End Sub