Loading ...
Sorry, an error occurred while loading the content.

Re: Index number of array element

Expand Messages
  • Flo
    ... Hi Eb, ... Thanks for these corrections, Eb! It s clear to see why the trailing delimiter is needed. Without that delimiter, Bert , in
    Message 1 of 16 , Feb 3, 2009
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "ebbtidalflats" <ebbtidalflats@...>
      wrote:
      >
      > Hi Flo,
      >
      > My original array index code was missing two extra arguments to the
      > StrCount function. That would generate a syntax error...

      Hi Eb,

      > Your code had a missing '%' to the name variable,...
      > The initial StrPos function had both the target variable AND
      > the array variable strings enclosed in delimiters. This
      > prevents the clip from finding false matches, where the target
      > starts off a longer array element. See 'Bert' below.

      Thanks for these corrections, Eb! It's clear to see why the trailing
      delimiter is needed. Without that delimiter, "Bert",
      in "Anthony|Bertha|Bert|Carla|David|Eb|Flo", is counted as #2. The
      solution is just another "|" in line #4 after ^%Name%.

      On this condition, however, we need another delimiter at the end of
      the array. Without this delimiter, "Flo" would be counted as "0".
      (Normally, a delimiter without a following value could cause some
      trouble but, in this case, it doesn't matter.)

      In my tests, this works fine...

      ^!SetListDelimiter |
      ^!SetArray %Array%=Anthony|Bertha|Bert|Carla|David|Eb|Flo|
      ^!Set %Name%=^?{(T=L)Select a name==^%Array%}
      ; long line start
      ^!Set %Index%=^$StrCount(|;^$StrCopyLeft(|^%Array%;^$StrPos(|^%Name%
      |;|^%Array%;1)$)$;0;1)$
      ; long line end
      ^!Info ^%Name% is number ^%Index%


      Flo
       
    • ebbtidalflats
      Hi Flo, Yes, you need an extra delimiter. However, I would NOT place it at the end of the array. That would require you to structure the array with this
      Message 2 of 16 , Feb 5, 2009
      • 0 Attachment
        Hi Flo,

        Yes, you need an extra delimiter. However, I would NOT place it at the
        end of the array. That would require you to structure the array with
        this particular code in mind, rather than make to index code work with
        ANY array.

        If you place the extra delimiter at the end of the array within the
        string position test, it will always be there, whether the array has a
        trailing delimiter or not. Extracting the StrPos function from your
        codeline (and adding quotes):

        ^$StrPos("|^%name%|";"|^%Array%|";1)$

        would parse as either (without trailing delimiter in array:

        ^$StrPos("|Flo|";"|Anthony|Bertha|Bert|Carla|David|Eb|Flo|";1)$

        or WITH trailing delimiter in the array:

        ^$StrPos("|Flo|";"|Anthony|Bertha|Bert|Carla|David|Eb|Flo||";1)$

        Then, when you count delimiters, you can drop the trailing delimiters:

        ; the whole long line start
        ^!Set
        %Index%=^$StrCount("|";"^$StrCopyLeft("|^%Array%";^$StrPos("|^%Name%|";"|^%Array%|";1)$)$";0;1)$
        ; long line end



        Cheers,


        Eb

        --- In ntb-clips@yahoogroups.com, "Flo" <flo.gehrke@...> wrote:
        >
        > Thanks for these corrections, Eb! It's clear to see why the trailing
        > delimiter is needed. Without that delimiter, "Bert",
        > in "Anthony|Bertha|Bert|Carla|David|Eb|Flo", is counted as #2. The
        > solution is just another "|" in line #4 after ^%Name%.
        >
        > On this condition, however, we need another delimiter at the end of
        > the array. Without this delimiter, "Flo" would be counted as "0".
        > (Normally, a delimiter without a following value could cause some
        > trouble but, in this case, it doesn't matter.)
        >
        > In my tests, this works fine...
        >
        > ^!SetListDelimiter |
        > ^!SetArray %Array%=Anthony|Bertha|Bert|Carla|David|Eb|Flo|
        > ^!Set %Name%=^?{(T=L)Select a name==^%Array%}
        > ; long line start
        > ^!Set %Index%=^$StrCount(|;^$StrCopyLeft(|^%Array%;^$StrPos(|^%Name%
        > |;|^%Array%;1)$)$;0;1)$
        > ; long line end
        > ^!Info ^%Name% is number ^%Index%
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.