4 Replies Latest reply on Feb 23, 2015 11:42 PM by bclake

    Does ProcessBook need focus when executing VBA Scripts? (Based off the state of MultiState Symbols)

    bclake

      I've got some basic ProcessBook VBA that works consistently during testing and while running on machines that aren't touched, but on machines that are utilized regularly (but leave PB up in the background) the VBA does not seem to be triggered.   Anyone had similar experiences with this, or guesses as to why it might happen?

       

      I even added some code in the VBA for logging and it seems like either I'm missing something in the trigger logic (that always works during testing) or there is some sort of issue with the VBA not getting triggered by a multi-state switch when ProcessBook is running in the background.

       

      Any insight, or suggestions on other ways to test would be great.

       

      Thanks!
      Brandon

       

       

      Extra Detail:

      The code that I want to trigger, and I'm worried is not getting triggered:

       

      Private Sub HA1_Zone1_StateChanged(bCancelDefault As Boolean)

      Sleep (1000)

      If (HA1_Zone1.GetMultiState.CurrentState > 1) Then Play_Sound Else No_ActionLogWrite

      End Sub

       

      HA1_Zone1_StateChanged is a multistate symbol, with only 2 states.  And it successfully triggers when I'm looking at ProcessBook.  Play_Sound works during testing, and No_ActionLogWrite is just putting some text into a notepad file.

        • Re: Does ProcessBook need focus when executing VBA Scripts? (Based off the state of MultiState Symbols)
          Kenji Hashimoto

          I created rectangle object with MultiState. I did Enable Scripting for this object and set the StateChanged method.

          I put the msgbox command and it works correctly.

          Private Sub Rectangle1_StateChanged(bCancelDefault As Boolean)

          MsgBox ("Test")

          End Sub

          In my environment, I did not focus to ProcessBook application but it showed MessageBox.

          The below screenshot, the focus is on PI SMT. Also PI ProcessBook is build mode but the MessageBox was appeared.

          I used PI ProcessBook 2014 3.4.0.251.

          Which version do you use?

          Does the other VB code work fine? (Is there any other issue with VBA?)

          For example, Display_DataUpdate was called every 5 seconds. (5 seconds is by default)

          Private Sub Display_DataUpdate()

          MsgBox ("test")

          End Sub

          If you set this function, does it work when PI ProcessBook does not have focus?

          1 of 1 people found this helpful
          • Re: Does ProcessBook need focus when executing VBA Scripts? (Based off the state of MultiState Symbols)
            gregor

            Hello Brandon,

             

            According to my experience ProcessBook is updating all open Displays including the ones in the background even ProcessBook application has no focus.

            I've confirmed the behavior using the following VBA code in a Test Display.

             

            Private Sub Display_DataUpdate()
                Dim mySrv As PISDK.Server
                Set mySrv = PISDK.Servers.DefaultServer
                Dim sDisplayName As String
                sDisplayName = ThisDisplay.Path
                Dim sLogTime As String
                sLogTime = Format(Now(), "dd-MMM-yyyy hh:mm-ss")
                mySrv.MessageLog.PutString (sDisplayName & " ===> DataUpdate has fired at " & sLogTime)
            End Sub
            

             

            For sure you need to save the display and add a reference to PI SDK Type Library. To monitor the local PI Message Log, please use pigetmsg -f in a command prompt, open another display and bring another application to front before bring the command prompt to front. With the default of Timer=5000, you should see messages each 5 seconds for about 30 minutes. After messages from our Test Display have stopped you will have about 10 minutes to activate it again. When you don't activate it within that period, sign-ups with PU Update Manager will become removed and the display will "freeze".

            KB00051 - PI ProcessBook display freezes, trend does not update, and values display number signs #### describes an alternative way of testing and the corresponding background information.

            1 of 1 people found this helpful
            • Re: Does ProcessBook need focus when executing VBA Scripts? (Based off the state of MultiState Symbols)
              bclake

              Thanks Kenji and Gregor.  I'll revamp my test and try a few more things like writing to the message log.  The display I was testing on used ProcessBook 2012 SP1  (3.3.1.1160) but I would be surprised if that was the issue.  After I add these indicators to the code I'll let you know how it goes.   Thanks for the tips.