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

Re: [Clip] Using arrays

Expand Messages
  • Alan_C
    ... In addition to the other, there has also been a problem with your logical construct. ... ^!Inc %Index% ^!If ^%Index% ^%Count% INFO ^!Goto LOOP ...
    Message 1 of 16 , Dec 19, 2006
    View Source
    • 0 Attachment
      On Tuesday 19 December 2006 10:32, Lee Underwood wrote:
      > Either way, the clip still doesn't work ...

      In addition to the other, there has also been a problem with your logical
      construct.

      :LOOP
      ^!Inc %Index%
      ^!If ^%Index% > ^%Count% INFO
      ^!Goto LOOP

      :INFO
      ^!InsertText=^%source%
      ^!If ^%source%=^%word^%IDX% DATES ELSE EXIT

      ; DATE PORTION IS HERE - WORKS FINE.

      the above (your original) can't iterate the array due to the array iteration
      line of code is not within a or your loop.

      you need to change your engineering to something *approximating* the next
      (mainly so as to get the array iteration line of code so that it's within a
      repetitive looping construct -- rather than within the "once only" (not
      looping) INFO block of code as you had originally had it.)

      :LOOP
      ^!Inc %Index%
      :INFO
      ^!If ^%source%=^%word^%Index%% DATES ELSE EXIT
      ^!If ^%Index% > ^%Count% DATES
      ^!Goto LOOP
      :DATES
      ^!InsertText=^%source%

      --
      Alan.
    • Alan_C
      ^!If ^%source%=^%word^%Index%% DATES ELSE EXIT Rather than the above, I d gotten in the habit of using the next instead of the above ^!IfSame ^%source%
      Message 2 of 16 , Dec 19, 2006
      View Source
      • 0 Attachment
        ^!If ^%source%=^%word^%Index%% DATES ELSE EXIT

        Rather than the above, I'd gotten in the habit of using the next instead of
        the above

        ^!IfSame "^%source%" "^%word^%Index%%" DATES ELSE EXIT
        --

        This is not Perl. But in Perl the upper foremost line is a potential (and big
        time) trap/pitfall.

        (In Perl the = (actually it's ==) is used only for number comparison, *not*
        for string comparison). eq is used in Perl for string comparison).

        So, in Notetab clip (just as at least some other languages do) I reserve the
        =, <, > those for number comparison only. But, then again, clips is a macro
        language, not a programming language. . . . which allows for "other" ways
        in which to do things (as in the next). So,

        However, I won't argue with you (as far as clips are concerned) providing your
        foremost line of code has been proven under all possible circumstances to be
        reliable.

        Just thought I'd mention that. Cya later.

        --
        Alan.
      • Alan_C
        ... In a case sensitive operating system (such as Linux) this would never fly. %word% (in Linux) would be a totally different variable than %Word% But perhaps
        Message 3 of 16 , Dec 19, 2006
        View Source
        • 0 Attachment
          On Monday 18 December 2006 10:22, Lee Underwood wrote:
          > ^!ClearVariables
          > ^!SetArray %Word%=
          > ^!Set %Count%=^%Word0%
          > ^!If ^%source%=^%word^%Index%% DATES ELSE EXIT

          In a case sensitive operating system (such as Linux) this would never fly.

          %word% (in Linux) would be a totally different variable than %Word%

          But perhaps Windows allows this; therefore, *perhaps* it will work.

          (mine habits from after learning to program for a while)

          (perhaps you didn't want to hear them)

          Nonetheless, the lesser the *potential* for a problem within any given chunk
          of code equates to a higher likelihood that such code will reliably
          accomplish the desired task that it was written for.

          --
          Alan.
        • acummingsus
          ... In a case sensitive operating system (such as Linux) this would never fly. %word% (in Linux) would be a totally different variable than %Word% But perhaps
          Message 4 of 16 , Dec 19, 2006
          View Source
          • 0 Attachment
            On Monday 18 December 2006 10:22, Lee Underwood wrote:
            > ^!ClearVariables
            > ^!SetArray %Word%=
            > ^!Set %Count%=^%Word0%
            > ^!If ^%source%=^%word^%Index%% DATES ELSE EXIT

            In a case sensitive operating system (such as Linux) this would
            never fly.

            %word% (in Linux) would be a totally different variable than %Word%

            But perhaps Windows allows this; therefore, *perhaps* it will work.

            (mine habits from after learning to program for a while)

            (perhaps you didn't want to hear them)

            Nonetheless, the lesser the *potential* for a problem within any
            given chunk
            of code equates to a higher likelihood that such code will reliably
            accomplish the desired task that it was written for.

            --
            Alan.
          • Lee Underwood
            Alan, Thanks. Using that I got it to work. I appreciate it. This gives me more understanding. Lee On 12/19/2006 03:33 PM, Alan_C wrote: ...
            Message 5 of 16 , Dec 19, 2006
            View Source
            • 0 Attachment
              Alan,

              Thanks. Using that I got it to work. I appreciate it. This gives me
              more understanding.

              Lee



              On 12/19/2006 03:33 PM, Alan_C wrote:
              ........................................................

              >On Tuesday 19 December 2006 10:32, Lee Underwood wrote:
              > > Either way, the clip still doesn't work ...
              >
              >In addition to the other, there has also been a problem with your logical
              >construct.
              >
              >:LOOP
              >^!Inc %Index%
              >^!If ^%Index% > ^%Count% INFO
              >^!Goto LOOP
              >
              >:INFO
              >^!InsertText=^%source%
              >^!If ^%source%=^%word^%IDX% DATES ELSE EXIT
              >
              >; DATE PORTION IS HERE - WORKS FINE.
              >
              >the above (your original) can't iterate the array due to the array iteration
              >line of code is not within a or your loop.
              >
              >you need to change your engineering to something *approximating* the next
              >(mainly so as to get the array iteration line of code so that it's within a
              >repetitive looping construct -- rather than within the "once only" (not
              >looping) INFO block of code as you had originally had it.)
              >
              >:LOOP
              >^!Inc %Index%
              >:INFO
              >^!If ^%source%=^%word^%Index%% DATES ELSE EXIT
              >^!If ^%Index% > ^%Count% DATES
              >^!Goto LOOP
              >:DATES
              >^!InsertText=^%source%
              >
              >--
              >Alan.
              >
              ........................................................
            • Lee Underwood
              Well, it only works on the first array item. When another one is selected, it just gives the source. Here is what I have: ^!ClearVariables ^!SetArray
              Message 6 of 16 , Dec 19, 2006
              View Source
              • 0 Attachment
                Well, it only works on the first array item. When another one is
                selected, it just gives the source. Here is what I have:

                ^!ClearVariables
                ^!SetArray %Word%=internetnews;Computerworld;eWeek;Government
                Technology;InfoWorld;Reuters;The Register;Web Pro News;Website
                Optimization;Yahoo News
                ^!Set %source%=^?{Enter Story Source=_internetnews|15 Seconds|4 Guys
                from Rolla|APIFinder|ASP 101|Computerworld|Database
                Journal|developer.com|DevX|E-Commerce
                Guide|eWeek|FlashKit|Gamelan|Government Technology|Graphics.com|HTML
                Goodies|InfoWorld|Java Boutique|PHP Builder|Reuters|The Register|Web
                Pro News|Website Optimization|Yahoo! News}
                ^!Set %Count%=^%Word0%
                ^!Set %Index%=0

                :LOOP
                ^!Inc %Index%

                :INFO
                ^!If ^%source%=^%Word^%Index%% DATES ELSE NEWS
                ^!If ^%Index% > ^%Count% DATES
                ^!Goto LOOP

                :NEWS
                ^!InsertText ^%source%
                ^!Goto EXIT

                :DATES
                ^!InsertText=^%source%
                ... etc. etc. ...

                ^!InsertText ,^%space%^%month% ^%d%, ^%y%


                Any ideas of how to get to the array items?
              • Alan_C
                ... ... ; where does the next line send/route the processing to? ... ; the above line assigns it to do either of two different potential tasks ... ;
                Message 7 of 16 , Dec 19, 2006
                View Source
                • 0 Attachment
                  On Tuesday 19 December 2006 17:34, Lee Underwood wrote:
                  > Well, it only works on the first array item. When another one is
                  > selected, it just gives the source. Here is what I have:
                  <snip>
                  > :LOOP
                  >
                  > ^!Inc %Index%
                  >
                  > :INFO
                  >

                  ; where does the next line send/route the processing to?

                  > ^!If ^%source%=^%Word^%Index%% DATES ELSE NEWS

                  ; the above line assigns it to do either of two different potential tasks

                  > ^!If ^%Index% > ^%Count% DATES
                  > ^!Goto LOOP
                  >
                  > :NEWS
                  >
                  > ^!InsertText ^%source%

                  ; answer: either is sent to here (NEWS label), does task then terminates

                  > ^!Goto EXIT

                  ; EXIT terminates, stops, ends the clip

                  >
                  > :DATES
                  >
                  > ^!InsertText=^%source%
                  > ... etc. etc. ...
                  >
                  > ^!InsertText ,^%space%^%month% ^%d%, ^%y%

                  ; or, answer is sent to here (DATES label), does task then terminates

                  ; oop, there's no more code here which means that the clip terminates, stops,
                  ends

                  > Any ideas of how to get to the array items?

                  As per my above comments in your code, Right now it's doing exactly what you
                  told it to do which is to *only* do *just once* through your loop, and then
                  do either of the two potentially assigned tasks, then terminate the clip's
                  run, stop, end exit.

                  ((you are parsing strings (text items), you are not parsing numbers. in
                  contrast or differently, numbers are digits, etc. the sort of stuff that
                  mathematical operations are performed on. -- you are not parsing numbers --
                  at least I don't see any numbers))

                  (it confuses me when I see someone use a mathematical operator (the =) to
                  parse strings. I prefer the ^!IfSame for strings. Just make sure that your
                  ^!If and your = is doing what you are expecting it to do. If not, then try
                  the ^!IfSame line that I enclosed)

                  The next code will exhaust all of the array items before ending the clip. In
                  the next, there is *only* one means with which to stop the clip -- I've
                  commented this important, critical EXIT line. Notice also that I moved this
                  critical line so that it's now located above your array processing line.

                  The Count is the number of array items. Once Index exceeds Count means that
                  all of the array items have been iterated/exhausted -- so, at this point we
                  can, in turn, stop the clip. If Index equals Count then it will do one more
                  loop, the very last loop and Index gets incremented again and then the next
                  loop the > (greater than) condition will be met which sends it to exit, stop.

                  :LOOP
                  ^!Inc %Index%

                  :INFO
                  ; exhaust the array and then exit
                  ^!If ^%Index% > ^%Count% EXIT
                  ; the above line is the only means with which to stop

                  ; the next line parses strings
                  ; ^!IfSame "^%source%" "^%word^%Index%%" DATES ELSE NEWS

                  ; does the next line work OK on strings?
                  ^!If ^%source%=^%Word^%Index%% DATES ELSE NEWS

                  :NEWS
                  ^!InsertText ^%source%
                  ^!Goto LOOP

                  :DATES
                  ^!InsertText=^%source%
                  ... etc. etc. ...
                  ^!InsertText ,^%space%^%month% ^%d%, ^%y%
                  ^!Goto LOOP
                  ; end of clip code

                  --
                  Alan.
                • Lee Underwood
                  Alan, Nope, that doesn t work either. Except for the first item in the array, each of the others are printed out twice. Items not in the array are printed out
                  Message 8 of 16 , Dec 20, 2006
                  View Source
                  • 0 Attachment
                    Alan,

                    Nope, that doesn't work either. Except for the first item in the
                    array, each of the others are printed out twice. Items not in the
                    array are printed out 10 times.

                    Lee


                    On 12/19/2006 10:19 PM, Alan_C wrote:
                    ........................................................

                    >As per my above comments in your code, Right now it's doing exactly what you
                    >told it to do which is to *only* do *just once* through your loop, and then
                    >do either of the two potentially assigned tasks, then terminate the clip's
                    >run, stop, end exit.
                    >
                    >((you are parsing strings (text items), you are not parsing numbers. in
                    >contrast or differently, numbers are digits, etc. the sort of stuff that
                    >mathematical operations are performed on. -- you are not parsing numbers --
                    >at least I don't see any numbers))
                    >
                    >(it confuses me when I see someone use a mathematical operator (the =) to
                    >parse strings. I prefer the ^!IfSame for strings. Just make sure that your
                    >^!If and your = is doing what you are expecting it to do. If not, then try
                    >the ^!IfSame line that I enclosed)
                    >
                    >The next code will exhaust all of the array items before ending the clip. In
                    >the next, there is *only* one means with which to stop the clip -- I've
                    >commented this important, critical EXIT line. Notice also that I moved this
                    >critical line so that it's now located above your array processing line.
                    >
                    >The Count is the number of array items. Once Index exceeds Count means that
                    >all of the array items have been iterated/exhausted -- so, at this point we
                    >can, in turn, stop the clip. If Index equals Count then it will do one more
                    >loop, the very last loop and Index gets incremented again and then the next
                    >loop the > (greater than) condition will be met which sends it to exit, stop.
                    >
                    >:LOOP
                    >^!Inc %Index%
                    >
                    >:INFO
                    >; exhaust the array and then exit
                    >^!If ^%Index% > ^%Count% EXIT
                    >; the above line is the only means with which to stop
                    >
                    >; the next line parses strings
                    >; ^!IfSame "^%source%" "^%word^%Index%%" DATES ELSE NEWS
                    >
                    >; does the next line work OK on strings?
                    >^!If ^%source%=^%Word^%Index%% DATES ELSE NEWS
                    >
                    >:NEWS
                    >^!InsertText ^%source%
                    >^!Goto LOOP
                    >
                    >:DATES
                    >^!InsertText=^%source%
                    >... etc. etc. ...
                    >^!InsertText ,^%space%^%month% ^%d%, ^%y%
                    >^!Goto LOOP
                    >; end of clip code
                    >
                    >--
                    >Alan.
                    >
                    >
                    ........................................................
                  • Alan_C
                    ... Oh. (I just now re looked at your original post of this thread) You wanted like an either or -- either print a match and date then exit --or-- (if no
                    Message 9 of 16 , Dec 20, 2006
                    View Source
                    • 0 Attachment
                      On Wednesday 20 December 2006 06:14, Lee Underwood wrote:
                      > Alan,
                      >
                      > Nope, that doesn't work either. Except for the first item in the
                      > array, each of the others are printed out twice. Items not in the
                      > array are printed out 10 times.

                      Oh. (I just now re looked at your original post of this thread) You wanted
                      like an "either or" -- either print a match and date then exit --or-- (if no
                      match found) print source then exit

                      The enclosed code is untested. I'm just trying to (quickly) help with the
                      logical construct.

                      Does the next code do that? ie iterate the array looking for a match, if a
                      match is found then do task in HAVE_MATCH label block then exit -- but if a
                      match is not found in the array then do task in the NO_MATCH label block then
                      exit


                      ; this code iterates array looking for a match of array item to ^%source%
                      ; if encounters a match, does HAVE_MATCH label block then exit
                      ; if does not encounter a match, does NO_MATCH label block then exit
                      ; thus exits via either of 2 label blocks: HAVE_MATCH or NO_MATCH
                      :LOOP
                      ^!Inc %Index%

                      :INFO
                      ; if a match not found then exit via NO_MATCH
                      ^!If ^%Index% > ^%Count% NO_MATCH

                      ; the next line parses strings
                      ; ^!IfSame "^%source%" "^%Word^%Index%%" HAVE_MATCH
                      ; ^!Goto LOOP

                      ; does the next line work OK on strings?
                      ^!If ^%source%=^%Word^%Index%% HAVE_MATCH
                      ^!Goto LOOP

                      ; formerly was NEWS
                      :NO_MATCH
                      ; no match was found
                      ; so do task here then exit
                      ^!InsertText ^%source%
                      ^!Goto Exit

                      ; formerly was DATES
                      :HAVE_MATCH
                      ; yes we found a match
                      ; so do task here then exit
                      ^!InsertText=^%source%
                      ... etc. etc. ...
                      ^!InsertText ,^%space%^%month% ^%d%, ^%y%
                      ^!Goto Exit
                      ; end of clip code

                      --
                      Alan.
                    • Lee Underwood
                      Ah, that does it. Thanks! I ll look at it in depth to get a better understanding. I appreciate it, Alan. Lee On 12/20/2006 03:32 PM, Alan_C wrote: ...
                      Message 10 of 16 , Dec 20, 2006
                      View Source
                      • 0 Attachment
                        Ah, that does it. Thanks! I'll look at it in depth to get a better
                        understanding. I appreciate it, Alan.

                        Lee


                        On 12/20/2006 03:32 PM, Alan_C wrote:
                        ........................................................
                        >Oh. (I just now re looked at your original post of this thread) You wanted
                        >like an "either or" -- either print a match and date then exit --or-- (if no
                        >match found) print source then exit
                        >
                        >The enclosed code is untested. I'm just trying to (quickly) help with the
                        >logical construct.
                        >
                        >Does the next code do that? ie iterate the array looking for a match, if a
                        >match is found then do task in HAVE_MATCH label block then exit -- but if a
                        >match is not found in the array then do task in the NO_MATCH label block then
                        >exit
                        >
                        >
                        >; this code iterates array looking for a match of array item to ^%source%
                        >; if encounters a match, does HAVE_MATCH label block then exit
                        >; if does not encounter a match, does NO_MATCH label block then exit
                        >; thus exits via either of 2 label blocks: HAVE_MATCH or NO_MATCH
                        >:LOOP
                        >^!Inc %Index%
                        >
                        >:INFO
                        >; if a match not found then exit via NO_MATCH
                        >^!If ^%Index% > ^%Count% NO_MATCH
                        >
                        >; the next line parses strings
                        >; ^!IfSame "^%source%" "^%Word^%Index%%" HAVE_MATCH
                        >; ^!Goto LOOP
                        >
                        >; does the next line work OK on strings?
                        >^!If ^%source%=^%Word^%Index%% HAVE_MATCH
                        >^!Goto LOOP
                        >
                        >; formerly was NEWS
                        >:NO_MATCH
                        >; no match was found
                        >; so do task here then exit
                        >^!InsertText ^%source%
                        >^!Goto Exit
                        >
                        >; formerly was DATES
                        >:HAVE_MATCH
                        >; yes we found a match
                        >; so do task here then exit
                        >^!InsertText=^%source%
                        >... etc. etc. ...
                        >^!InsertText ,^%space%^%month% ^%d%, ^%y%
                        >^!Goto Exit
                        >; end of clip code
                        >
                        >--
                        >Alan.
                        >
                        ........................................................
                      Your message has been successfully submitted and would be delivered to recipients shortly.