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

[Clip] Re: How might I do this math with a clip?

Expand Messages
  • Don Passenger
    Here is what I wound up with. To test it take the data from yesterday and repeat it a couple of times but changing field two for every successive set (and
    Message 1 of 12 , Nov 5, 2003
      Here is what I wound up with. To test it take the data from yesterday
      and repeat it a couple of times but changing field two for every
      successive set (and deleting the one word line at the top as I
      eventually insert that at the bottom.

      I used Hugo's method of building a variable with multiple lines, padding
      short numbers with zeros and then sorting before dumping into an array.
      There is an error in my clip because in several cases the last number
      is corrupted. I didn't track it down, I fixed those three or four
      problems manually. Because it was a corruption of the last number in
      the set, it was thrown out in almost all cases.

      ;Jump to Start
      ^!Jump TEXT_START
      ;Clear all Variables
      ^!ClearVariables

      ;set the delimiter to the pipe
      ;think a lot of this unneccessary but copied
      ;from Jody's noteblock clip
      ^!Set %Delimiter%=|
      ^!Set %Delimiter%=^$StrReplace("|";"^%Vbar%";"^%Delimiter%";0;0)$
      ^!SetDelimiter ^%Delimiter%

      ;Field1 is the field we check for school
      ;n is a counter
      ^!Set %n%=0; %Field1%=2

      ;make sure there is something there
      ^!IfTrue ^$IsEmpty(^$GetField(^$GetRow$;1)$)$ Oops
      ^!SetHintInfo Getting field...
      ^!SetScreenUpdate Off

      :NewTeam
      ;grab current cursor position
      ^!Set %CurCur%=^$GetRow$:^$GetCol$
      ;first time set team
      ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
      ^!Set %Team%=^$GetSelection$
      ^!ClearVariable %testarray%

      :Loop
      ;get place for this line
      ^!Set %GrabField1%=^$GetField(^$GetRow$;1)$
      ^!Set %Place%=^$GetSelection$
      ;get team for this line
      ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
      ;be sure that this line is for current team
      ;if not, go to ProcessTeam
      ;otherwise continue here
      ^!If "^%Team%" <> "^$GetSelection$" ProcessTeam
      ;use Hugo's ideas to get places and pad with zeros
      ^!Set %Field%=^$GetField(^$GetRow$;1)$
      ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
      ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
      ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
      ; --------64 AND 203 PUTS 204 ON TOP -----------------
      ;use Hugo's ideas to set the place variable
      ^!Append %FirstFields%="^%Field%"^%NL%
      ^!Jump +1
      ^!GoTo Loop

      :ProcessTeam
      ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
      ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
      ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%Fields5%
      ^!Set %Result%=^$Calc(^%LowestFive%)$
      ^!Jump LINE_START
      ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
      ^!ClearVariables
      ^!Continue continue?

      ^!GoTo NewTeam
    • hugo_paulissen
      ... Don, If you re asking for feedback, I cannot give any; your clip doesn t work (Fields are not filled, so I end up with several plusses and error in
      Message 2 of 12 , Nov 5, 2003
        --- In ntb-clips@yahoogroups.com, Don Passenger <dpasseng@i...> wrote:
        > Here is what I wound up with.

        Don,

        If you're asking for feedback, I cannot give any; your clip doesn't
        work (Fields are not filled, so I end up with several plusses and
        error in expression...)

        Hugo
      • Don Passenger
        Feedback would be good. The clip worked for me with the one exception of groups where the highest data element was used because somehow I added extra s to
        Message 3 of 12 , Nov 5, 2003
          Feedback would be good.
          The clip worked for me with the one exception of groups where the
          highest data element was used because somehow I added extra "'s to the
          last element in my array. I think I maybe changed my data element order
          from the prior example without realizing it.

          Here is some data:

          312|Albion| 445|Soltis Mike|17:14.15|05:20.65|10:59.90|16:39.25
          318|Albion| 453|Tom Jurasek|17:14.95|05:12.80|10:54.60|16:44.00
          344|Albion| 495|Chris Jurasek|17:23.60|05:21.45|11:06.45|16:49.40
          509|Albion| 704|Aaron Parson|18:02.05|05:28.50|11:28.70|17:33.15
          519|Albion| 716|Zakk Havens|18:05.65|05:22.50|11:26.50|17:29.95
          601|Albion| 811|Christoff Russell|18:35.20|05:37.60|11:48.50|18:02.00
          710|Albion| 931|Domonique Craig|19:49.15|05:55.30|12:31.80|19:09.60
          140|Allendale| 195|Alex Hanes|16:34.45|05:23.50|10:50.65|16:08.15
          172|Allendale| 255|Rob Klingeman|16:45.05|05:22.15|10:51.10|16:13.30
          329|Allendale| 474|Jacob Betts|17:18.45|05:26.60|11:08.20|16:47.05
          375|Allendale| 538|Clinton VanderMolen|17:30.30|05:26.05|11:09.75|16:57.25
          469|Allendale| 654|Alex MacDonaold|17:51.00|05:37.90|11:34.95|17:20.70

          Notice what it does with the one with only 5 entries (here Allendale).
          Problem with the last element in the array.
          I get this:
          Allendale: 140+172+329+375+"469";=[error in expression]
        • Alan C.
          ... ; ============here============================== ; (tagged thusly below) try either append line, watch difference ;
          Message 4 of 12 , Nov 5, 2003
            On Wed, 05 Nov 2003 20:07:52 -0500, Don Passenger wrote:
            >�Feedback would be good.
            >�The clip worked for me with the one exception of groups where the
            >�highest data element was used because somehow I added extra "'s to the
            >�last element in my array.

            ; ============here==============================
            ; (tagged thusly below) try either append line, watch difference
            ; ============here==============================

            (the pair of quotes in the one append line)

            +, cleaned out some unneeded set stuff that wasn't used after it was set
            maybe you can un comment the screen update line again if you want.
            --

            ^!Jump TEXT_START
            ;Clear all Variables
            ^!ClearVariables
            ^!Set %Delimiter%=|
            ^!Set %Delimiter%=^$StrReplace("|";"^%Vbar%";"^%Delimiter%";0;0)$
            ^!SetDelimiter ^%Delimiter%

            ;make sure there is something there
            ^!IfTrue ^$IsEmpty(^$GetField(^$GetRow$;1)$)$ Oops
            ^!SetHintInfo Getting field...
            ; ^!SetScreenUpdate Off

            :NewTeam
            ;first time set team
            ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
            ^!Set %Team%=^$GetSelection$

            :Loop
            ;get place for this line
            ^!Set %GrabField1%=^$GetField(^$GetRow$;1)$
            ^!Set %Place%=^$GetSelection$
            ;get team for this line
            ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
            ;be sure that this line is for current team
            ;if not, go to ProcessTeam
            ;otherwise continue here
            ^!If "^%Team%" <> "^$GetSelection$" ProcessTeam
            ;use Hugo's ideas to get places and pad with zeros
            ^!Set %Field%=^$GetField(^$GetRow$;1)$
            ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
            ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
            ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
            ; --------64 AND 203 PUTS 204 ON TOP -----------------
            ;use Hugo's ideas to set the place variable


            ; ============here==============================
            ; ^!Append %FirstFields%="^%Field%"^%NL%
            ^!Append %FirstFields%=^%Field%^%NL%
            ^!Info ^%FirstFields%
            ; ============here==============================


            ^!Jump +1
            ^!GoTo Loop

            :ProcessTeam
            ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
            ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
            ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%Fields5%
            ^!Set %Result%=^$Calc(^%LowestFive%)$
            ^!Jump LINE_START
            ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
            ; ^!ClearVariables
            ^!ClearVariable %FirstFields%
            ^!Continue continue?

            ^!GoTo NewTeam
            ; ----<end

            --
            Alan.
          • hugo_paulissen
            Don, Alan, It has to do with the quotes... The last item of array ^%Fields% is incorrect. 312 ; 318 ; 344 ; 509 ; 519 ; 601 ; 710 ;
            Message 5 of 12 , Nov 6, 2003
              Don, Alan,

              It has to do with the quotes...

              The last item of array ^%Fields% is incorrect.

              "312";"318";"344";"509";"519";"601";""710";"
              "140";"172";"329";"375";""469";"

              If this happens with value 6 or 7 you will not notice this, since
              these values are disregarded when you do the addition. Obviously
              this will lead to the error reported if there are only five
              rows/values.

              ^!Append %FirstFields%="^%Field%"^%NL% adds a new line to the
              last element of an array, and that's where the problem starts,
              because the replace expression

              ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$

              puts a semicolon at the end of the line. Apparently the array
              expects something new after this and (thus?) puts a quote around the
              last real element. If you were to do the same replace operation with
              the regular replace-box you would have this

              "312";"318";"344";"509";"519";"601";"710";

              which differs from the line at the top...

              My option would be to delete the last semicolon before continuing.

              If you add the following line

              ^!Set %Fields%="^$strTrim(^%Fields%)$"

              (quotes were needed) you strip off all the extra's. At the end you'll
              find the new code for that part of your clip.

              As Alan already mentioned there are some variables that you don't
              use anymore (CurCur for instance) and there should be a nice way
              to terminate the operation of the clip automatically (I used
              getlinecount in the original version, but if there are empty lines
              at the end there should happen some additional checking...).

              :ProcessTeam
              ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
              ; -------------- ADDED -------------- start
              ; Some ^!Info shows you what's happening with the values
              ;^!Info var Fields is:^%NL%^%Fields%
              ^!Set %Fields%="^$strTrim(^%Fields%)$"
              ;^!Info trimmed var Fields is:^%NL% ^%Fields%
              ; -------------- ADDED -------------- end
              ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
              ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%
              Fields5%
              ;END INFO
              ^!Set %Result%=^$Calc(^%LowestFive%)$
              ^!Jump LINE_START
              ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
              ^!ClearVariables
              ^!Continue continue?

              Regards,

              Hugo
            • Don Passenger
              ^!Append %FirstFields%= ^%Field% ^%NL% changed to ^!Append %FirstFields%=^%Field%^%NL% which I think corrects the problem I was having
              Message 6 of 12 , Nov 6, 2003
                ^!Append %FirstFields%="^%Field%"^%NL%
                changed to
                ^!Append %FirstFields%=^%Field%^%NL%
                which I think corrects the problem I was having
              • hugo_paulissen
                ... Ha! I do not remember why I inserted the quotes in the first place, but it did have something to do with the x ; y -like structure of an array. If it
                Message 7 of 12 , Nov 6, 2003
                  > ^!Append %FirstFields%="^%Field%"^%NL%
                  > changed to
                  > ^!Append %FirstFields%=^%Field%^%NL%
                  > which I think corrects the problem I was having

                  Ha! I do not remember why I inserted the quotes in the first place,
                  but it did have something to do with the "x";"y"-like structure of an
                  array.

                  If it works...

                  Hugo
                Your message has been successfully submitted and would be delivered to recipients shortly.