6 Replies Latest reply on Feb 9, 2012 11:08 AM by RJKSolutions

    Display.Symbols.Item("") method case sensitivity...any way around it

    gkrueger

      Does anyone know if there is a way around the case sensitivity of the Symbols collection .Item("item name") method?  I have some code that is failing due to that, and when I try to rename the offending object, it keeps reverting back to the original name (ie when I change txtVes1_Val1 to txtVes1_val1 for a text symbol object on the display, and then save it, when i open it again, the name is back to txtVes1_Val1).

       

      I have a workaround using a For Each to parse all the symbols in the display, but I was hoping to use the .Item method as it's probably faster and makes for cleaner code.

       

      Any tips appreciated.

       

      Thanks,

       

      -Greg

       

       

        • Re: Display.Symbols.Item("") method case sensitivity...any way around it
          gkrueger

          I forgot to mention, when I try to do the rename, it gives me an "ambiguous name detected" error.  

           

          I thought it might be due to the fact I have the object in a global collection, but I commented out the code that was filling that collection and I still can't rename the objects.  The display does not have that many objects on it, so I'm sure there isn't another one of the same name already there.

           

          Any clues about what that error means and how to resolve it would be great.

           

          -Greg

            • Re: Display.Symbols.Item("") method case sensitivity...any way around it

              The name of symbol is the unique identifier for symbols on a display, and from memory (or snooping  at OSIsoft's code ) the symbol names are stored in lower case.  So you can't make direct case changes to a symbol name, you need to change it e.g. add some characters to the end, then change the case, and then finally remove the characters you added.

               

              Edit: When I say stored, what I meant to say was the comparison of names in the Symbols collection is performed in lower case.

                • Re: Display.Symbols.Item("") method case sensitivity...any way around it
                  gkrueger

                  Rhys,

                   

                  Thanks for the tip...that fixed the issue with the rename.

                   

                  Just curious, if the checking for duplicates by PB internally is all done in lower case, any idea why the .Item method is case sensitive.  I just did a quick check to see if I use an LCASE() on the symbol name I'm using, whether that fixes it, but it didn't

                   

                  Just for reference, the command I'm trying to run is

                   

                  Set tmpSymbol = Me.Symbols.Item("Symbol_Name")

                   

                  if the object is named Symbol_name in the PB designer Properties, then that command fails

                    • Re: Display.Symbols.Item("") method case sensitivity...any way around it

                      That is one for David from OSIsoft to answer.  I would assume that there are two code paths used for interrogating the symbols collection.

                        • Re: Display.Symbols.Item("") method case sensitivity...any way around it
                          dhollebeek

                          Well, hi there, Rhys :)

                           

                          This isn't a definitive answer, but I think it will explain enough.  After some research and playing around, I think this issue all comes down to the differences between PB and VBA.  PB is case-sensitive, but VBA is not.  If you use automation to change names of symbols, you can indeed change a symbol's name from "UPPER" to "upper" without generating an error.  All collections in PB work like this (including the internal ones we use for keeping track of displays, toolbars, etc.)  However, VBA is NOT case sensitive, so if you use the symbol property window to rename a symbol, you get that ambiguous error (which is coming from VBA, not PB).  Since we have no control over how VBA works, I don't see how we'd be able to fix this issue (the workaround is to use automation and not the UI).  The Item routine, however, has to be case sensitive, because PB itself is.  For example, the following code is entirely legal:

                           
                          Sub foo()
                              Dim sym As Symbol
                              Dim sym2 As Symbol
                                  
                              Set sym = ThisDisplay.Symbols.Add(pbSymbolArc)
                              sym.NAME = "NAME"
                              Set sym2 = ThisDisplay.Symbols.Add(pbSymbolArc)
                              sym2.NAME = "name"
                          End Sub
                          

                           This will result in 2 symbols on the display, one named "NAME" and one named "name".  If the Item routine were case insensitive, you wouldn't be able to specify which of these 2 symbols you were referring to.

                           

                          I hope at least some of that made sense ....

                           

                          -D