4 Replies Latest reply on Jun 13, 2017 8:01 PM by Bille

    Hi Everyone, I need to replicate a VBA code for status of rotating gear for 3 different processbooks. On linking them with buttons, One runs perfectly fine but switching to a 2nd display the gear doesn't run. Any help on this..

    Bille

      Hi Everyone, I need to replicate a VBA code for status of rotating gear for 3 different PI processbooks accessed with buttons to switch windows of views, One runs perfectly fine but switching to a 2nd display the gear doesn't run. Any help on this..

        • Re: Hi Everyone, I need to replicate a VBA code for status of rotating gear for 3 different processbooks. On linking them with buttons, One runs perfectly fine but switching to a 2nd display the gear doesn't run. Any help on this..
          pmartin

          Hello,

           

          Open up the VBA editor on the second display.  Does the logic appear to be the same as the first display?  If so, try stepping through the code to see if everything makes sense.  If you need help with any of this, let me know and I can explain in more detail.

          • Re: Hi Everyone, I need to replicate a VBA code for status of rotating gear for 3 different processbooks. On linking them with buttons, One runs perfectly fine but switching to a 2nd display the gear doesn't run. Any help on this..
            Bille

            Hello Paul,

             

            Thanks for the response. The vba code for both is same except the Multistate Value for the different processbooks. I have 3 processbooks linked with buttons. The status of the gear is controlled by a value. See below the vba code for display 2 n 3:

            Private Declare Function clock Lib "Msvcrt.dll" () As Long

             

            ============================================================================

            ' This is the timer period, and can be adjusted to give a longer or shorter period between animation frames

            Const Milliseconds = 62.5

             

             

            Private Sub AnimateFan1(ByVal IsRunning As Boolean)

             

             

                Dim t1 As Long

                Dim i As Integer

               

                For i = 1 To 39 ' This should be adjusted based on the value of the Milliseconds constant. See below for more info

                ' To make sure that we can stop the animation on multistate change, the number of loops we iterate through should be

                ' (ProcessBook data refresh interval (Default 5000 milliseconds) / value of Milliseconds / 2) - 1

                ' For example: (5000 / 125 / 2) - 1 = 19

                    If IsRunning Then

                        ' Toggle which icon is visible during each animation frame duration

                       

                        ' Frame 1

                        Gearanimationframe4_1.Visible = True

                        Gearanimationframe3_1.Visible = False

                        t1 = clock() + Milliseconds

                        ' Start the timer

                        While clock() < t1

                            DoEvents

                        Wend

                       

                        ' Frame 2

                        Gearanimationframe4_1.Visible = False

                        Gearanimationframe3_1.Visible = True

                        t1 = clock() + Milliseconds

                        ' Start the timer

                        While clock() < t1

                            DoEvents

                        Wend

                       

                    Else

                        ' Just set one of the icons visible to indicate no activity

                        Gearanimationframe4_1.Visible = True

                        Gearanimationframe3_1.Visible = False

                    End If

                Next

               

            End Sub

             

             

            Private Sub Display_DataUpdate()

             

             

             

                Dim MyMultiState1 As MultiState

             

             

                Set MyMultiState1 = ThisDisplay.Symbols("Value18").GetMultiState

                If MyMultiState1.CurrentState > 1 Then

                    Call AnimateFan1(True)

                Else

                    Call AnimateFan1(False)

                End If

               

               

            End Sub

            ==================================================================================

            Screen Display 2 VBA code:

             

            Private Declare Function clock Lib "Msvcrt.dll" () As Long

             

             

            ' This is the timer period, and can be adjusted to give a longer or shorter period between animation frames

            Const Milliseconds = 62.5

             

             

            Private Sub AnimateFan1(ByVal IsRunning As Boolean)

             

             

                Dim t1 As Long

                Dim i As Integer

               

                For i = 1 To 39 ' This should be adjusted based on the value of the Milliseconds constant. See below for more info

                ' To make sure that we can stop the animation on multistate change, the number of loops we iterate through should be

                ' (ProcessBook data refresh interval (Default 5000 milliseconds) / value of Milliseconds / 2) - 1

                ' For example: (5000 / 125 / 2) - 1 = 19

                    If IsRunning Then

                        ' Toggle which icon is visible during each animation frame duration

                       

                        ' Frame 1

                        Gearanimationframe4_1.Visible = True

                        Gearanimationframe3_1.Visible = False

                        t1 = clock() + Milliseconds

                        ' Start the timer

                        While clock() < t1

                            DoEvents

                        Wend

                       

                        ' Frame 2

                        Gearanimationframe4_1.Visible = False

                        Gearanimationframe3_1.Visible = True

                        t1 = clock() + Milliseconds

                        ' Start the timer

                        While clock() < t1

                            DoEvents

                        Wend

                       

                    Else

                        ' Just set one of the icons visible to indicate no activity

                        Gearanimationframe4_1.Visible = True

                        Gearanimationframe3_1.Visible = False

                    End If

                Next

               

            End Sub

             

             

            Private Sub Display_DataUpdate()

             

                Dim MyMultiState1 As MultiState

             

             

                Set MyMultiState1 = ThisDisplay.Symbols("Value13").GetMultiState

                If MyMultiState1.CurrentState > 1 Then

                    Call AnimateFan1(True)

                Else

                    Call AnimateFan1(False)

                End If

               

                End Sub

             

             

             

             

            Gear.JPG

            Regards

             

            Bill