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

Re: [Clip] Re: Making numbers line up

Expand Messages
  • Stephen
    Hi Folks, I just had to write a clip for this too. Everyone had tried just about all the gambits except for manipulating strings so I did that. In my test, for
    Message 1 of 7 , Apr 2, 2001
    • 0 Attachment
      Hi Folks,
      I just had to write a clip for this too.
      Everyone had tried just about all the gambits except for manipulating
      strings so I did that.
      In my test, for 981 lines it runs two seconds slower than Wheeler's, but
      you don't have to tell the clip anything, it figures out how long lines
      should be for you, so it may all work out.
      Also for some reason or other, I could not understand the logic of the
      timer sections so in order to understand them, re-wrote them.
      Anyway for your criticism or whatever, here it is:

      H="Make numbers line up, String version"
      ^!SetListDelimiter ":"
      ^!SetArray %start%=^$GetDate(hh:mm:ss)$
      ^!SetListDelimiter ^%EMPTY%
      ^!Set %count%=1; %lastspace%=10; %wordsize%=5; %text%=^$GetText$
      :sizeup
      ; Loop determines longest line.
      ; Loop determines longest last word
      ; Note that thisspace and thissize are not arrays, but can be treated
      like them
      ; for the purposes of this clip.
      ^!Set %temp1%=^$StrPosRight(" ";"^$GetParagraph(^%count%)$";FALSE)$
      ; Loop determines the greatest value of last space
      ^!If ^%temp1%>^%lastspace% NEXT ELSE SKIP
      ^!Set %lastspace%=^%temp1%
      ; Loop determines greatest value of wordsize
      ^!Set %temp2%=^$StrSize("^$GetParagraph(^%count%)$")$
      ^!Set %temp2%=^$Calc(^%temp2%-^%temp1%)$
      ^!If ^%temp2%>^%wordsize% NEXT ELSE SKIP
      ^!Set %wordsize%=^%temp2%
      ; Set a series of variables to hold thisspace and thissize values
      ^!Set %thisspace^%count%%=^%temp1%; %thissize^%count%%=^%temp2%
      ^!Inc %count%
      ^!If ^%count%>^$GetTextLineCount$ NEXT ELSE sizeup
      ; FORMATTING SECTION (note semicolons anywhere in the text
      ; will screw things up so we do a workaround.)
      ^!Set %counter%=0; %output%=^%EMPTY%
      ^!Set %text%="^$StrReplace("^%NL%";"; ";^%text%;FALSE;FALSE)$"
      ^!SetArray %text%=^%text%
      :format
      ^!Inc %counter%
      ^!If ^%counter% >= ^%count% writeit
      ; For each element in the text array,
      ; Loop determines how many spaces to add
      ^!Set
      %add%=^$Calc((^%lastspace%-^%thisspace^%counter%%)+(^%wordsize%-^%thissize^%counter%%))$
      ; Loop inserts them.
      ^!Set %where%="^$StrPosRight(" ";"^%text^%counter%%";FALSE)$"
      ^!Append %output%=^%NL%^$StrInsert("^$StrFill("
      ";^%add%)$";"^%text^%counter%%";^%where%)$
      ^!GoTo format
      :writeit
      ^!Toolbar Clear All
      ^%output%
      :Timer Section
      ^!SetListDelimiter ":"
      ^!SetArray %end%=^$GetDate(hh:mm:ss)$
      ^!If ^%end1%<^%start1% NEXT ELSE SKIP
      ^!Inc ^%end1% 24
      ^!Set %temp1%=^$Calc((360 * ^%start1%)+ (60 * ^%start2%)+(^%start3%))$;
      %temp2%=^$Calc((360 * ^%end1%) +(60 * ^%end2%)+(^%end3%))$
      ^!Set %totalsecs%=^$Calc(^%temp2%-^%temp1%)$
      ^!Set %hours%=^$Calc((^%totalsecs%) DIV (360))$
      ^!Set %minutes%=^$Calc((^%totalsecs% - (^%hours% * 360 )) DIV (60))$
      ^!Set %seconds%=^$Calc(^%totalsecs% - ((^%hours% * 360) + (^%minutes% *
      60)))$
      ^!Info Lines Formatted:^t^%NL%^%NL%^%Count%^%NL%^%NL%Start
      Time:^t^%start%^%NL%End Time:^t^%end%^%NL%Run
      Time:^t^%hours%:^%minutes%:^%seconds%
    • wheeler54321@yahoo.com
      Hi Stephen! I tested your clip, it does the job. But the output looks a little ... Line1: 234 Line2: 5678 Line3: 9101112 Line4: 1234 ... Line1:
      Message 2 of 7 , Apr 2, 2001
      • 0 Attachment
        Hi Stephen!

        I tested your clip, it does the job. But the output looks a little
        different with extra space. For Instance:

        -----------Original
        Line1: 234
        Line2: 5678
        Line3: 9101112
        Line4: 1234
        -------------------

        ----------Output

        Line1: 234
        Line2: 5678
        Line3: 9101112
        Line4: 1234
        -------------------

        Is there something I overlooked?

        To anybody who is interested-
        When fixing long lines:

        > ^!Append %output%=^%NL%^$StrInsert("^$StrFill("
        > ";^%add%)$";"^%text^%counter%%";^%where%)$

        Note the space between " "
        ...^$StrInsert("^$StrFill(" ";^%add%)$";"^%text....

        wheeler
      • Stephen
        Hi Wheeler, I just don t know why it does that, but I noticed that every one of the clips except yours have little oddities. (Sigh). I ll look at it and
        Message 3 of 7 , Apr 2, 2001
        • 0 Attachment
          Hi Wheeler,
          I just don't know why it does that, but I noticed that every one of the
          clips except yours have little oddities. (Sigh). I'll look at it and
          figure out exactly what is the problem. Probably where the clip decides
          how many spaces to add on each line. If it were in the section where the
          clip figures out how long the lines should be then there should be
          either more variation or similiar string length for all line.
          Thanks,
          Stephen

          wheeler54321@... wrote:
          >
          > Hi Stephen!
          >
          > I tested your clip, it does the job. But the output looks a little
          > different with extra space.
          . . .
        • Stephen
          Hi Wheeler, Figured it out, The problem is that I was using ; as a list delimiter which added an extra space to every line but the first one. Line 27 should
          Message 4 of 7 , Apr 2, 2001
          • 0 Attachment
            Hi Wheeler,
            Figured it out,
            The problem is that I was using "; " as a list delimiter which added an
            extra space to every line but the first one.
            Line 27 should be:
            ^!Set %text%="^$StrReplace("^%NL%";";";^%text%;FALSE;FALSE)$"
            instead of
            ^!Set %text%="^$StrReplace("^%NL%";"; ";^%text%;FALSE;FALSE)$"

            Also, if the clip were thorough, it would somewhere add a routine to
            keep semicolons somewhere in the text from screwing up the format.
            Later,
            Stephen

            wheeler54321@... wrote:
            >
            > Hi Stephen!
            >
            > I tested your clip, it does the job. But the output looks a little
            > different with extra space. For Instance:
          • wheeler54321@yahoo.com
            Hi Stephen! ... Sweet! I will have to use your clip as a sample for some upcoming projects. Good Job! wheeler
            Message 5 of 7 , Apr 2, 2001
            • 0 Attachment
              Hi Stephen!
              > Figured it out,

              Sweet! I will have to use your clip as a sample for some upcoming
              projects.

              Good Job!

              wheeler
            • Stephen
              Flattery? Thanks
              Message 6 of 7 , Apr 3, 2001
              • 0 Attachment
                Flattery?
                Thanks

                wheeler54321@... wrote:
                > I will have to use your clip as a sample for some upcoming
                > projects.
                >
                > Good Job!
                >
                > wheeler
                >
              • thefrank
                Hi Stephen , I tested your clip using same file as other tests. 1000 lines formatted in 25 seconds! Nice job. Using String methods certainly handles some of
                Message 7 of 7 , Apr 3, 2001
                • 0 Attachment
                  Hi Stephen ,

                  I tested your clip using same file as other tests. 1000 lines
                  formatted in 25 seconds! Nice job. Using String methods certainly
                  handles some of the quirks inherent in other methods (after all, they
                  are strings...) but is is strange to watch the cursor just sit there
                  while the statusbar does all the work. (ahem..)

                  I did have several newlines after the last text which did get counted
                  in the final result, so if an accurate count is needed I suppose they
                  will need to be trimmed.

                  The only plausible argument (that I can think of) for presetting the
                  RightMargin is if large batches of similar data needs to be formatted
                  consistently over several sets, the longest line in one set may not
                  be the same as another, or from batch to batch.

                  Presetting the right limit would keep the output consistent over the
                  long haul and improve readability, especially if the output pages are
                  bound, or otherwise collated.

                  All in all, itsa nice clip that works fine, and I learned some string
                  stuff too.

                  Regards,

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