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

Re: [Clip] add column

Expand Messages
  • Jody
    Hi Michael, Hello everybody! Just a note to let you know I will get to the posts that need answering as I can. Had a great time in Tampa. It was great to see
    Message 1 of 6 , Jul 16, 2000
      Hi Michael,

      Hello everybody! Just a note to let you know I will get to the
      posts that need answering as I can. Had a great time in Tampa.
      It was great to see Eric again!!! Michael, see below.

      >I have a fixed text file with no delimiters.
      > 1271 rows deep. characters 56-67 are money amounts with decimal
      > and two places to right of decimal.
      >
      > I'd like to add the entire amount.
      >
      > I've noticed before that NoteTab seems to have a limit to how
      > many rows it can calculate at a time - have had to break up
      > into chunks and then add the sums together. Is this the norm?

      Yes, NoteTab only accepts about 325 characters when calculating.
      My NoteBlock will add an unlimited amount of figures in a column
      (perhaps theoretically). The problem with using it is it needs a
      delimiter and you say you don't have any. Perhaps you can modify
      "Add Field..." Clip to copy a selection, paste new, and then use
      field one with any delimiter. It should work.

      http://www.sureword.com/notetab/zip/noteblock.zip

      Happy Clip'n!
      Jody

      http://www.sureword.com/notetab

      Subscribe, UnSubscribe, Options
      mailto:Ntb-Clips-Subscribe@...
      mailto:Ntb-Clips-UnSubscribe@...
      http://www.egroups.com/group/ntb-clips
    • RS
      Hi Michael, I posted this on Friday, but I didn t receive a copy from eGroups, so I guess it wasn t distributed. It is there on the web, though: message # 4057
      Message 2 of 6 , Jul 16, 2000
        Hi Michael,

        I posted this on Friday, but I didn't receive a copy from eGroups, so I
        guess it wasn't distributed. It is there on the web, though: message # 4057
        Fri Jul 14, 2000 9:41am - http://www.egroups.com/messages/ntb-clips

        Here it goes again:


        At 10:56 PM 07/13/00 -0400, you wrote:

        >I have a fixed text file with no delimiters.
        >1271 rows deep. characters 56-67 are money amounts with decimal and two
        >places to right of decimal.
        >
        >I'd like to add the entire amount.

        There is a DoToLines component available from my page (
        http://home.att.net/~ptools/main/index.htm ). Using it is quite easy to do
        what you had in mind.

        I acknowledge that the component might be confusing for some users, and I
        intend to make it more direct whenever I have the time. Particularly, the
        ":Finish" label is misleading: it should be named ":Continue". There are
        examples on the component's use, however, on my page. And the following is
        another one. Look at it, compare it with the bare component, and you'll
        know how to use it in the future.

        Of course, ClipWriter is a big help, too. I wrote and tested this in 10
        minutes:

        ;======== Start ========
        H="Add Fields"
        ; RS - Last edited: 07/14/00
        ; Edited with ClipWriter


        ;RS 1998 - DoToLines
        ; Download other components for NoteTab from:
        ; http://home.att.net/~ptools/main/components.htm


        ^!ClearVariables
        ^!Set %line%=1
        :Loop
        ^!SetCursor ^%line%:1

        ;===============================================
        ;
        ;INSERT BELOW THE NEXT DOTED LINE YOUR CODE
        ; FOR WHATEVER HAS TO BE DONE TO EACH LINE:
        ; (Use the Finish label to conditionally avoid a line)
        ;
        ;==================================================
        ;@ ===== BEGIN CODE =================================
        ;The value to add is in the 12 characters starting at
        ;position 56:
        ^!Set %x%=^$StrCopy("^$GetLine(^%line%)$";56;12)$
        ^!Append %s%=^%x%^%NL%
        ^!Set %sum%=^$Calc(^%sum% + ^%x%;4)$
        ;@ ===== END CODE ===================================
        ;==================================================
        ;This is the rest of the routine -
        ;DO NOT WRITE BELOW.
        ;===============================================
        :Finish
        ^!Inc %line%
        ^!If ^%line% <= ^$GetLineCount$ Loop
        ^!StatusClose
        ;***********************
        ;@ FINALIZATION Code below here.
        ;Display the values gathered and the total:
        ^!Info ^%s% ^p sum = ^%sum%
        ;========= End =========





        I tested with the following sample text (it would have been nice if you had
        given us a sample -- writing it took me almost as long as writing the clip):

        *************************
        qwerty qwerty qwerty qwerty qwerty qwerty qwerty qwert 1234567.2345 more
        qwerty END OF LINE
        qwerty qwerty qwerty qwerty qwerty qwerty qwerty qwert 1234.95 more
        qwerty END OF LINE
        qwerty qwerty qwerty qwerty qwerty qwerty qwerty qwert 345.76 more
        qwerty END OF LINE
        qwerty qwerty qwerty qwerty qwerty qwerty qwerty qwert 11.23 more
        qwerty END OF LINE
        qwerty qwerty qwerty qwerty qwerty qwerty qwerty qwert 34.2382 more
        qwerty END OF LINE
        *************************

        The displayed result is:

        1234567.2345
        1234.95
        345.76
        11.23
        34.2382

        sum = 1236193.4127




        Regards,

        RS

        ======================================================

        ClipWriter 2.12 -- Millennium Edition

        http://home.att.net/~ptools/ClipWriter/cw.htm


        The easiest way to program NoteTab, and
        ...a powerful tool for quick Clip solutions!



        ======================================================







        ======================================================
      • Michael Gerholdt
        Hi, Ramon, Thanks for this clip. Never ceases to amaze me how simply some apparently difficult tasks can be solved. I did have one problem and it took me a
        Message 3 of 6 , Jul 18, 2000
          Hi, Ramon,

          Thanks for this clip. Never ceases to amaze me how simply some apparently
          difficult tasks can be solved.

          I did have one problem and it took me a while to isolate the actual cause.
          The records I have invariably have an empty line at the bottom of the file,
          which was causing this to produce "error in expression" for the final sum.

          The fix was to remove the equal sign from:

          ^!If ^%line% <= ^$GetLineCount$ Loop

          so that when it becomes equal it stops then instead of looping one more
          (fatal) time.

          Thanks again for your time and assistance.

          Michael Gerholdt
        • RS
          Hello Michael, ... Glad to help. :) ... Good point! Taking it one step further then, there s no way one can tell there will be just one empty line at the end.
          Message 4 of 6 , Jul 19, 2000
            Hello Michael,

            At 09:26 AM 07/18/00 -0400, you wrote:


            >Thanks for this clip.

            Glad to help. :)


            >I did have one problem and it took me a while to isolate the actual cause.
            >The records I have invariably have an empty line at the bottom of the file,
            >which was causing this to produce "error in expression" for the final sum.
            >
            >The fix was to remove the equal sign from:
            >
            >^!If ^%line% <= ^$GetLineCount$ Loop
            >
            >so that when it becomes equal it stops then instead of looping one more
            >(fatal) time.


            Good point!



            Taking it one step further then, there's no way one can tell there will be
            just one empty line at the end. So I added this piece of code to filter out
            trailing empty lines:

            =========
            ;//Find last non-empty line:
            ^!Set %iLast%=^$GetLineCount$
            :LoopLastLine
            ^!If ^$GetLine(^%iLast%)$ <> "" LookForFirstLine
            ^!Dec %iLast%
            ^!Goto LoopLastLine
            :LookForFirstLine
            ==========

            Then, the DoNext label will check for %iLast% being matched, instead of
            ^$GetLineCount$, which is also more efficient:

            ==========
            :DoNext
            ^!Inc %line%
            ^!If ^%line% < ^%iLast% Loop
            ==========


            And how about empty lines at the beginning? These other piece can take care
            of that:

            ==========
            ;//Find First non-empty line:
            ^!Set %iFirst%=1
            :LoopFirstLine
            ^!If ^$GetLine(^%iFirst%)$ <> "" Next1
            ^!Inc %iFirst%
            ^!Goto LoopFirstLine
            :Next1
            ==========

            Then, at the Next1 label, we assign %iFirst% to the %line% variable of the
            DotoLines component, so it will start recursing lines at that position. We
            also adjust the %iLast% variable, which was decremented one unit more than
            needed at the time the loop was exited, to point to the last non empty line:

            ==========
            :Next1
            ^!Inc %iLast%
            ^!Set %line%=^%iFirst%
            ==========

            The next step would be to weed out lines not containing a number at the
            specified field position. That should be done at the beginning and at the
            end, as we did for empty lines. This will allow us to have comments at the
            beginning of the file, or even at the end. Checking for those lines in the
            middle of the document would slow down the clip too much to be advisable,
            so it should be the responsibility of the user to take care that all the
            lines in the middle contain the expected field in the expected place. But
            all that could remain on the to-do list for the time being, I guess ...



            In the meantime, here's the new clip that will ignore the empty lines:

            ;======== Start ========
            H="Add Fields3"

            ;*: ---- start long line: ----
            ^$* WARNING: This clip contains 1 long lines. DELETE THIS WARNING LINE
            after making sure long lines are not split, to be able to run the clip. If
            this line is not broken the others are fine, too. To have broken lines
            automatically fixed, download the free Clip Toys utilities from:
            http://ptools.home.att.net/ClipToys/ClipToys.htm
            ;*. ---- end long line ----

            ; RS - Last edited: 07/19/00
            ; Edited with ClipWriter

            ; Adds value in field at pos %iFieldStart%
            ; Field's size should be %iFieldLength%
            ;Empty lines at beginning and end of file are ignored.

            ;RS 1998 - DoToLines
            ; Download other components for NoteTab from:
            ; http://home.att.net/~ptools/main/components.htm

            ^!ClearVariables
            ; *** USER DEFINED FIELD ***
            ;DEFINE POS OF FIELD TO ADD:
            ^!Set %iFieldStart%=56
            ;DEFINE LENGTH OF FIELD TO ADD:
            ^!Set %iFieldLength%=12


            ; *** Start processing ***
            ;Find last non-empty line:
            ^!Set %iLast%=^$GetLineCount$
            :LoopLastLine
            ^!If ^$GetLine(^%iLast%)$ <> "" LookForFirstLine
            ^!Dec %iLast%
            ^!Goto LoopLastLine

            :LookForFirstLine
            ;Find First non-empty line:
            ^!Set %iFirst%=1
            :LoopFirstLine
            ^!If ^$GetLine(^%iFirst%)$ <> "" Next1
            ^!Inc %iFirst%
            ^!Goto LoopFirstLine


            :Next1
            ^!Inc %iLast%
            ^!Set %line%=^%iFirst%
            :Loop
            ^!SetCursor ^%line%:1

            ;===============================================
            ;
            ;INSERT BELOW THE NEXT DOTED LINE YOUR CODE
            ; FOR WHATEVER HAS TO BE DONE TO EACH LINE:
            ; (Use the DoNext label to conditionally avoid a line)
            ;
            ;==================================================
            ;@ ===== BEGIN CODE =================================
            ;The value to add is in the 12 characters starting at
            ;position 56:
            ;*: ---- start long line: ----
            ^!Set %x%=^$StrCopy("^$GetLine(^%line%)$";^%iFieldStart%;^%iFieldLength%)$
            ;*. ---- end long line ----
            ^!Append %s%=^%x%^%NL%
            ^!Set %sum%=^$Calc(^%sum% + ^%x%;4)$
            ;@ ===== END CODE ===================================
            ;==================================================
            ;This is the rest of the routine -
            ;DO NOT WRITE BELOW.
            ;===============================================
            :DoNext
            ^!Inc %line%
            ^!If ^%line% < ^%iLast% Loop

            ^!StatusClose
            ;***********************
            ;@ FINALIZATION Code below here.
            ;Display the values gathered and the total:
            ^!Info ^%s% ^p sum = ^%sum%

            ;========= End =========


            Regards,

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