12 Replies Latest reply on Apr 1, 2011 4:08 AM by Sanjeeb

    Auto saving VBA in a Process Book display

    Sanjeeb

      Hi,

       

      I have a peculiar issue. I have created a PB display with dropdown buttons inserted in the display. This has been kept in a remote server and users who have access to this page have READ ONLY rights. Whenever a user makes some selection in the dropdown and goes out of this display without saving (since she doesn't have WRITE access to this page) and comes back again, she won't see her last selection/changes which is pretty obvious. Please note that whenever some change is made to the dropdown a value is being written to the corresponding PI Tag.

       

      Let me sight an example: I have a dropdown control wherein I have 2 items, say, "AVAILABLE" and "REMOVE". The values for "AVAILABLE" and "REMOVE" are 0 and 1 respectively. Say, a PI Tag being used is AveRem.PV. The user chooses,say,"REMOVE" and thus 1 is written down to AveRem.PV. Now, since the user doesn't have WRITE access i.e. she can't save this display, whenever she goes out of the display and comes back again she still sees "AVAILABLE" and not "REMOVE" as per her last selection. This is obvious since she couldn't save the display once she made changes in the display for it to take effect.

       

      My question is, is there a way to auto save a display as and when some changes are made on the display? In that case, the user who doesn't have WRITE access to this page won't bother much and once she makes some changes in the dropdown and goes out without saving and once she comes back, she would see the last selection made (i.e. in this example above she would see "REMOVE" per her last selection and not AVAILABLE).

       

      Regards,Sanjeeb

       

       

        • Re: Auto saving VBA in a Process Book display
          hanyong

          Hi Sanjeeb,

           

          Something that is going through my mind as I'm reading your post. Wouldn't it make sense to read and display the snapshot value of the tag (AveRem.PV) in the dropdown control when the display is opened?

           

           

           

           

            • Re: Auto saving VBA in a Process Book display
              Sanjeeb

              Hi Han,

               

              You mean displaying the value instead of the text i.e. 0=AVAILABLE and 1=REMOVE...

               

              The requirement is to display these texts and not the value.

               

              Please let me know if I meant otherwise...

               

              Thanks.

                • Re: Auto saving VBA in a Process Book display
                  hanyong

                  What I mean is that you can read the snapshot value of the tag (0 or 1) from the PI Server when the display is opened. And according to the value that is read, display either AVAILABLE or REMOVE, instead of saving the last selection within the display. This way, what the user see will be the most updated value of the tag in the PI Server.

                    • Re: Auto saving VBA in a Process Book display
                      Sanjeeb

                      This is the code I am using. Can you please let me this?

                       
                      Private Sub ComboBox1_DropButtonClick()
                      
                      On Error GoTo ErrorHandler
                      
                      Dim ptmTimestamp As New PITimeServer.PITimeFormat
                      
                      Dim pvValueToAdd As PISDK.PIValue
                      
                      Dim ptPIPoint As PISDK.PIPoint
                      
                      Dim piserver As Server
                      
                      Dim myvalue As PIValue
                      
                      Set piserver = PISDK.Servers("BKMPICOLL")
                      
                      Set pvValueToAdd = New PISDK.PIValue
                      
                      Set ptPIPoint = piserver.PIPoints("TEST_TAG")
                      
                      Set myvalue = ptPIPoint.Data.Snapshot
                      
                      ptmTimestamp.InputString = Now()
                      
                      Set pvValueToAdd.TimeStamp = ptmTimestamp
                      
                      If ComboBox1.Value = "Available" Then
                      
                      pvValueToAdd.Value = 0
                      
                      ElseIf ComboBox1.Value = "Remove" Then
                      
                      pvValueToAdd.Value = 1
                      
                      End If
                      
                      ptPIPoint.Data.UpdateValue pvValueToAdd, 0
                      
                      pvValueToAdd.Value = 0
                      
                      Set pvValueToAdd = Nothing
                      
                      Set ptPIPoint = Nothing
                      
                      Exit Sub
                      
                      ErrorHandler:
                      
                        MsgBox Err.Description, vbApplicationModal + vbCritical, "Application Error"
                      
                      End Sub
                      
                      Private Sub Display_Open()
                      
                      ComboBox1.AddItem "Available"
                      
                      ComboBox1.AddItem "Remove"
                      
                      End Sub
                      

                       

                        • Re: Auto saving VBA in a Process Book display
                          andreas

                          Sanjeeb,

                           

                          you could use a digital tag that shows Available/Remove in the Trend or Value object. If you need to use the integer for other reasons, here are the suggested changes. We move some of the variables out of the procedures to the general level:

                           
                          ' Explicitly define any variables
                          Option Explicit
                          
                          ' The PI Server
                          Dim piserver As PISDK.Server
                          ' The PI Point
                          Dim ptPIPoint As PISDK.PIPoint
                          ' The Snapshot
                          Dim myvalue As PISDK.PIValue
                          

                           Than we modify the Display_Open to preset the ComboBox:

                           
                          Private Sub Display_Open()
                              ' Load the ComboBox
                              ComboBox1.AddItem "Available"
                              ComboBox1.AddItem "Remove"
                              ' Set the PI Server
                              Set piserver = PISDK.Servers("W2K3")
                              ' Set the PI Point
                              Set ptPIPoint = piserver.PIPoints("TEST_TAG_I")
                              ' Get the Snapshot
                              Set myvalue = ptPIPoint.Data.Snapshot
                              ' Set the ComboBox to the Snapshot
                              If myvalue.Value = 0 Then
                                  ComboBox1.Value = "Availble"
                              Else
                                  ComboBox1.Value = "Remove"
                              End If
                          End Sub
                          

                           Finally I have simplified your write code a bit:

                           
                          Private Sub ComboBox1_DropButtonClick()
                              ' Error Handler
                              On Error GoTo ErrorHandler
                              ' Write the Value
                              If ComboBox1.Value = "Available" Then
                                  ptPIPoint.Data.UpdateValue 0, Now()
                              Else
                                  If ComboBox1.Value = "Remove" Then
                                      ptPIPoint.Data.UpdateValue 1, Now()
                                  End If
                              End If
                              ' Exit
                              Exit Sub
                              ' Error Handler
                          ErrorHandler:
                              MsgBox Err.Description, vbApplicationModal + vbCritical, "Application Error"
                              Exit Sub
                          End Sub
                          

                           Hope this helps.

                            • Re: Auto saving VBA in a Process Book display
                              Sanjeeb

                              Thanks Andreas. It works perfectly fine.

                               

                              Regards,

                               

                              Sanjeeb

                                • Re: Auto saving VBA in a Process Book display
                                  Sanjeeb

                                  Hi Andreas,

                                   

                                  I was testing for couple of drodown boxes and more than that but seemed like it wasn't picking up the last selected item from the dropdown. It works fine for one dropdown in the script(like the one above).

                                   

                                  I think I need to make some changes in the script,like,defining more number of "myvalue" etc when I define "option explicit".Do you think that will work or I need to make some other changes? Appreciate all your inputs/suggestions.

                                   

                                  Many thanks.

                                   

                                  Sanjeeb

                                    • Re: Auto saving VBA in a Process Book display
                                      andreas

                                      Sanjeeb,

                                       

                                      not sure what you are trying to achieve. If you have multiple combo boxes, and you are writing to multiple tags, you may have to define multiple value and tag objects.

                                       

                                      The purpose of "Option Explicit" is to force variable definition, this avoids typos and by definition of variables and the type you change the "responsibility" for the code more to your side than VBA :-)

                                       

                                      Also, the code implicitly expects just two values in the combobox and in the tag value (I did a simple if-then-else instead of your if-then-else-if-then).

                                        • Re: Auto saving VBA in a Process Book display
                                          Sanjeeb

                                          Andreas, yes, you got me right. And I have done the same just after posting you my last reply.This now perfectly suits my requirement. Thanks again for your prompt reply.

                                           

                                          Sanjeeb

                                            • Re: Auto saving VBA in a Process Book display
                                              Sanjeeb

                                              Hi,

                                               

                                              Something on saving/not-saving the display. My user requirement is like below:

                                               

                                              I have a display wherein I have VBA scripts,trends and few controls. Whenever I open the display it opens up with * attached to it. For ex, I have a display DISPLAY.PDI and whenever I open this it opens like DISPLAY.PDI* which is because it needs to be saved.

                                               

                                              Now, whenever I make some change in the display, say, make change in the controls(say, a dropdown control), this PDI automatically goes into unsave mode. When I go out of this display the message would pop-up saying "Do you want to Save...yes/no"...i.e. the regular message box. If I the WRITE access to the folder where I have kept the display then I can save it..else no.

                                               

                                              Now, the remote user who uses this display doesn't have WRITE permission. He can't save even if he sees the message box. Is there a way not to display the message box? I.E. when the user makes changes and go out this message box shouldn't appear. Is that doable somewhere in Processbook.ini file or anywhere else?

                                               

                                              Appreciate all your respnses.

                                               

                                              Regards,

                                               

                                              Sanjeeb