9 Replies Latest reply on Jun 6, 2008 5:57 AM by UdoGre

    Getting the name of a property

    Level 7
      There's got to be an easy way to do this, but it escapes me. Say I've got a
      property list:

      pList = [#AB:123,#BC:456,#DE:789]

      Okay, so say I want to know what the name of the nth property is?
      Basically, I want to be able to put in a "2" and have it return "#BC" or
      possibly "BC", either will do. I know any number of ways to get the "456"
      out of there, but what I want is the property name, not its value.


        • 1. Re: Getting the name of a property
          Level 7
          pList.getPropAt(2)
          pList.getOne(456)
          • 2. Re: Getting the name of a property
            Level 7
            > pList.getPropAt(2)
            > pList.getOne(456)

            Thanks. (The first was what I was looking for. GetOne only works if I know
            the value already.)


            • 3. Re: Getting the name of a property
              Level 7
              Okay, related question. Now let's say I want to do the opposite. So I
              have: (Values and symbol names are purely arbitrary.)

              pList = [#AB:123,#BC:456,#DE:789]

              And I want to know the location of a given property on the list. So I want
              to input "#BC" and have it return "2". I can't do a GetOne() in this case,
              because A.) I don't know the values on the list in advance, and B.) It's
              possible that multiple values may be equal. GetPropAt() doesn't work
              either, because it does the opposite. GetProp() returns the value of the
              property, not the position. (Not even sure what the point of that is - why
              would I ever type "pList.getProp(#BC)" when I could more easily type just
              "pList.BC"?) GetAt() and GetAProp() seem to do the same thing as GetProp()
              (with the exception that GetAProp() returns 0 instead of erroring if the
              property doesn't exist). What am I missing here?


              • 4. Re: Getting the name of a property
                Level 7
                If you know the value you are looking for, you can use getPos()

                pList = [#AB:123,#BC:456,#DE:789]
                put pList.getPos(456)
                -- 2

                So, if you know the property name, you can do a 2 stage check:

                put pList.getPos(pList[#BC])
                -- 2
                • 5. Re: Getting the name of a property
                  Level 7
                  > If you know the value you are looking for, you can use getPos()
                  >
                  > pList = [#AB:123,#BC:456,#DE:789]
                  > put pList.getPos(456)
                  > -- 2
                  >
                  > So, if you know the property name, you can do a 2 stage check:
                  >
                  > put pList.getPos(pList[#BC])
                  > -- 2

                  Yes, but as I said, that won't work if there's more than one of the same
                  value in the list. Take this for example:

                  pList = [#AB:123,#BC:456,#DE:789,#FG:456]
                  put pList.getPos(pList[#FG])
                  --2

                  This fails because it just goes for the first 456 in the list. I'm asking
                  for the position of #FG, and should get 4, but I get 2 instead.


                  • 6. Re: Getting the name of a property
                    Level 7
                    You'll probably have to loop through the list then

                    on getPosFromProp vList,vProp
                    propCount=vList.count
                    repeat with i=1 to propCount
                    if vList.getPropAt(i)=vProp then return i
                    end repeat
                    return void
                    end

                    pList = [#AB:123,#BC:456,#DE:789,#FG:456]
                    put getPosFromProp(pList,#FG)
                    -- 4
                    • 7. Re: Getting the name of a property
                      UdoGre Level 1
                      Hi,

                      Maybe I missed something, but why not use findpos?

                      pList = [#AB:123,#BC:456,#DE:789,#FG:456]
                      put pList.findPos(#FG)
                      -- 4

                      That's on Mx04.

                      HTH,

                      Udo
                      • 8. Re: Getting the name of a property
                        Level 7
                        > Maybe I missed something, but why not use findpos?
                        >
                        > pList = [#AB:123,#BC:456,#DE:789,#FG:456]
                        > put pList.findPos(#FG)
                        > -- 4

                        I *knew* there had to be a way short of looping through the list. Thanks.
                        Go figure it doesn't start with "get", and thus isn't found anywhere near
                        the other related functions in the alphabetical list. It also doesn't seem
                        to be linked from the "See also:" sections in any of the other related pages
                        in the help-files. I wouldn't be surprised if this feature isn't widely
                        known...


                        • 9. Re: Getting the name of a property
                          UdoGre Level 1
                          Hi,

                          I also needed the help file for this, but when typing in "property list" in the search, it was among 9 hits there ;-)

                          Udo