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

[Clip] Re: Array manipulation (was Do these functions exist?)

Expand Messages
  • Charles A. Brannon
    eric g.v. fookes wrote: original article:http://www.egroups.com/group/ntb-clips/?start=2602 ... ... Actually, it was very helpful, but
    Message 1 of 18 , Feb 8, 2000
    • 0 Attachment
      "eric g.v. fookes" <fooke-@...> wrote:
      original article:http://www.egroups.com/group/ntb-clips/?start=2602

      ...
      > Surprise... you can ;-) Just assign the text returned by the
      > function to an array variable. Example:
      >
      > ^!SetListDelimiter ^p
      > ^!SetArray %Array%=^$GetFileText(FileName)$
      >
      > Each line will be stored in an individual cell of the array.
      > You can then access a specific line by using the following
      > syntax: ^%Array[n]%, where n represents the line number. To
      > access line #3, you would write ^%Array3%.
      >
      > Hope this helps.
      ...

      Actually, it was very helpful, but thanks should go to
      Grandma Kay first for suggesting $GetFileText()$ which led me to
      the proper help file page that suggested the same procedure.
      What I am doing is porting a random signature generator to
      NoteTab. This application chooses a random record from a tag
      file (one or more lines, %-delimeted), and prints it formatted
      with user information, etc, etc. Standard stuff.

      I would like to read the number if records (subscripts in
      the array) directly. One obvious (indirect) solution would be to
      loop through the file, record by record, and count each one in
      turn. Another would be to loop through the array, comparing each
      subscript to a null or empty string. The problem with the first
      is speed, and it clearly defeats the purpose of the
      $GetFileText()$ call in the first place. The second method does
      not take into account an empty record (^P%^P%^P), which may
      exist and must be dealt with more gracefully than by truncating
      possible values.

      The question I've been leading to is this: how can I read
      the size (in subscripts) of an array that may or may not have
      the same number of subscripts as the file has lines? I can read
      the number of lines in a file, but with variable size records,
      this does not match the actual number of records. Any
      suggestions would be appreciated.

      -- Charles
    • lmhamilton@juno.com
      On Tue, 08 Feb 2000 11:53:35 -0800 Charles A. Brannon writes: ... Charles, Here is something SMYRU shared with me last summer
      Message 2 of 18 , Feb 8, 2000
      • 0 Attachment
        On Tue, 08 Feb 2000 11:53:35 -0800 "Charles A. Brannon"
        <cabrannon@...> writes:
        <snip>
        > The question I've been leading to is this: how can I read
        > the size (in subscripts) of an array that may or may not have
        > the same number of subscripts as the file has lines? I can read
        > the number of lines in a file, but with variable size records,
        > this does not match the actual number of records. Any
        > suggestions would be appreciated.
        >
        > -- Charles

        Charles,

        Here is something SMYRU shared with me last summer for my use. This is
        modified from the original he offered, for my specific file. I have some
        other clips added on to it, but you can see in the top 2/3 the basics of
        how it works. It is designed to give me the ability to generate text
        pages for those members with e-mail addresses in a mailto: format, and it
        they do not have an e-mail address to put them in with no mailto:
        formatting. also, if I want a page of just those with an e-mail address,
        I comment out the line after ";do nothing".

        ******Start Clip*******
        ; --- starts base routine ---
        ^!Set %_%=1
        ^!SetListDelimiter ^p
        ^!Set %file%=^?{(T=O;F="My base file|*.*")Point the source of base}
        ^!SetArray %All%=^$GetFileText(^%file%)$
        ^!Toolbar New document
        ^!SetScreenUpdate Off

        :get_line
        ^!If ^%All0% < ^%_% no_more_lines
        ^!SetListDelimiter |
        ^!SetArray %Line%=^%All^%_%%
        ^!Inc %_%
        ; --- ends base routine ---
        ;^!IfFalse ^%Line3% do_nothing

        ;Long lines follow:
        ;RECORD_DATE|LAST|FIRST|JR_ETC|LINE_2|SALUTATION|ADDRESS|CITY|COUNTY|STAT
        E|ZIPCODE|EMAIL|WEB_PAGE|MEMBER|SINCE|EXPIRATION|HOME_PHONE|COUNTRY
        ^%NL%^%line14%|^%Line6% ^%Line3% ^%Line2% ^%Line4%
        ^%Line5%|^%line12%|^%Line7% ^%Line8%, ^%Line9% ^%Line10% ^%Line11%,
        ^%Line18%|^%line17%|^%Line16%
        ;Long Lines end.

        ^!Goto get_line

        :do_nothing
        ^%NL%^%Line1%|^%Line2%|^%Line4%|^%Line5%|^%Line6%
        ^!Goto get_line

        :no_more_lines
        ^!SetCursor 1:1
        ^!Keyboard Delete

        ;From Jody Adair, 06/18/99
        ^!Replace " " >> "" WAS
        ^!IfError NEXT else Skip_-1
        ;Added by me:
        ^!Replace "^P " >> "^P" WAS
        ^!IfError NEXT else Skip_-1
        ^!SetWordWrap False
        ^!Jump TEXT_END
        ^!Keyboard ENTER
        ^!Replace "<a href="mailto:E-MAIL">NAME</a>" >> "NAME" WAS
        ^!Clip "Remove #http"
        ^!Find "||||^P" WAS
        ^!Jump TEXT_END
        ^!KEYBOARD BACKSPACE
        ^!IfError END
        ^!Keyboard DELETE
        ^!ClearVariables
        ^!Goto END
        *****End clip******

        Hope this helps.


        Larry Hamilton, Jr. lmhamilton@...
        Hamilton National Genealogical Society, Inc.
        http://www.HamiltonGenSociety.org/
        My Web Site: http://notlimaH.tripod.com

        ________________________________________________________________
        YOU'RE PAYING TOO MUCH FOR THE INTERNET!
        Juno now offers FREE Internet Access!
        Try it today - there's no risk! For your FREE software, visit:
        http://dl.www.juno.com/get/tagj.
      • Charles A. Brannon
        lmhamilto-@juno.com wrote: original article:http://www.egroups.com/group/ntb-clips/?start=2611 ... - - - - - EXACTLY! - - - - - By reading this code (sorry, I
        Message 3 of 18 , Feb 8, 2000
        • 0 Attachment
          lmhamilto-@... wrote:
          original article:http://www.egroups.com/group/ntb-clips/?start=2611

          ...

          > <cabrannon@...> writes:
          > > how can I read
          > > the size (in subscripts) of an array that may or may not have
          > > the same number of subscripts as the file has lines?

          ...

          > ^!SetArray %All%=^$GetFileText(^%file%)$

          ...

          > ^!If ^%All0% < ^%_% no_more_lines

          ...

          > Hope this helps.

          - - - - - EXACTLY! - - - - -

          By reading this code (sorry, I usually ignore comments ;-p ),
          I gleaned that the subscript zero (0) held the array size and I
          was right! Thanks for you help. By using *exact* array size
          rather than some obscure and arbitrary counting mechanism, I
          chopped about six lines of code off the program (not counting
          spacing and comments). It grabs a random number from NoteTab with
          the range of one through array[0] --

          ^!Set this=^$Calc(RND(^%that0%) + 1;0)$

          -- which is exactly what I was looking to to.

          Thanks again.

          Now to set a timer and auto-generate...

          BTW, please note (for all those interested) that the variable
          set by the above ^!Set statement was *not* surrounded. The naked
          variable name works, too.
        • Eb Guenther
          Hi Larry, and all, A month or so ago Larry Hamilton posted a clip about array manipulation, containing (snipped to the pertinent part). ... How does NTP know
          Message 4 of 18 , Mar 12, 2000
          • 0 Attachment
            Hi Larry, and all,

            A month or so ago Larry Hamilton posted a clip about array
            manipulation, containing (snipped to the pertinent part).
            It took me this long to realize that I had a question(;-):

            >^!SetListDelimiter ^p
            >^!SetArray %All%=^$GetFileText("some file name")$
            >
            >:get_line
            >^!SetListDelimiter |
            >^!SetArray %Line%=^%All^%x%%
            >^!Inc %x%
            > . . .
            >^!Goto get_line


            How does NTP know that the first array's delimiter
            is "^P" and the second array's delimiter is "|"?

            Are there any situations, where NTP would lose track?

            Subroutines? Far clips? Change of INI files?
            Other?


            TIA,


            Eb

            Note: Everything outside of my PGP signature is a forgery.
          • Jody
            Hi Eb, ... Because that is what you are telling it to use for the delimiter. The default is ; In the first every time NoteTab sees a ^p in the criteria it
            Message 5 of 18 , Mar 12, 2000
            • 0 Attachment
              Hi Eb,

              > A month or so ago Larry Hamilton posted a clip about array
              > manipulation, containing (snipped to the pertinent part). It
              > took me this long to realize that I had a question(;-):
              >
              >>^!SetListDelimiter ^p
              >>^!SetArray %All%=^$GetFileText("some file name")$
              >>
              >>:get_line
              >>^!SetListDelimiter |
              >>^!SetArray %Line%=^%All^%x%%

              > How does NTP know that the first array's delimiter
              > is "^P" and the second array's delimiter is "|"?

              Because that is what you are telling it to use for the delimiter.
              The default is ";" In the first every time NoteTab sees a ^p in
              the criteria it considers everything up to that point one field
              in the delimited text. In the case of the Clip Larry sent it was
              a mailto: list. He then had another list delimited by a "|" to
              work with so he need to switch delimiters to tell NoteTab how to
              handle that list. You will see more examples of it in DirStuff
              and other Clips posted, especially when the Clip makes a list of
              file paths\names and then puts them into a NoteTab Wizard to
              choose from. Normally the ^p and | combo is used then.

              > Are there any situations, where NTP would lose track?

              Not that I am aware of except maybe if the Library is exited. I
              would have to test to give a definite answer though.

              Happy Clip'n!
              Jody

              http://www.sureword.com/notetab

              Subscribe, UnSubscribe, Options
              mailto:Ntb-Clips-Subscribe@...
              mailto:Ntb-Clips-UnSubscribe@...
              http://www.egroups.com/list/ntb-clips
            • Eb Guenther
              Hi Jody, Thanks for the explanation. I ve been thinking that I would need to change delimiters back and forth in each iteration of a loop, and now gather that
              Message 6 of 18 , Mar 12, 2000
              • 0 Attachment
                Hi Jody,

                Thanks for the explanation. I've been thinking that
                I would need to change delimiters back and forth in each
                iteration of a loop, and now gather that this is not
                needed.


                This is good news.

                Cheers,


                eb



                Note: Everything outside of my PGP signature is a forgery.
                What? no PGP signature? Then the whole message is forged!
              • Lawrence M Hamilton, Jr.
                Hi Eb, ... The first array is filled before it goes to the next array. This particular example was developed by someone else, and I customized it to a very
                Message 7 of 18 , Mar 12, 2000
                • 0 Attachment
                  Hi Eb,

                  On Sun, 12 Mar 2000 13:30:53 -0600 Eb Guenther <ebg@...> writes:
                  > Hi Larry, and all,
                  >
                  > A month or so ago Larry Hamilton posted a clip about array
                  > manipulation, containing (snipped to the pertinent part).
                  > It took me this long to realize that I had a question(;-):
                  >
                  > >^!SetListDelimiter ^p
                  > >^!SetArray %All%=^$GetFileText("some file name")$
                  > >
                  > >:get_line
                  > >^!SetListDelimiter |
                  > >^!SetArray %Line%=^%All^%x%%
                  > >^!Inc %x%
                  > > . . .
                  > >^!Goto get_line
                  >
                  >
                  > How does NTP know that the first array's delimiter
                  > is "^P" and the second array's delimiter is "|"?

                  The first array is filled before it goes to the next array.


                  This particular example was developed by someone else, and I customized
                  it to a very narrow use.

                  I think I finally understand it myself.<grin>

                  The first array %all% uses ^P as its delimiter, in other words, each line
                  is an element of the array ^%all%

                  The clip then reads each line, and uses a second array, %Line%, that uses
                  | as the delimiter, and it reads each element from each line which is the
                  same as each element of the array %all%.

                  The array %all% does not get overwritten or modified throughout the clip,
                  but each time that the variable %x% is incremented, it changes the value
                  of %Line%, because %line% can have a variable number of elements.

                  In the narrow way I use it, I have a text file of individuals, some have
                  an e-mail address and some do not. By modifying one line in the clip, I
                  can either get a list of all individuals, or just a list of those with
                  e-mail addreses, and then I can perform other actions based on which kind
                  of list it is.

                  Hope This Helps.


                  Larry Hamilton, Jr. lmhamilton@...
                  Hamilton National Genealogical Society, Inc.
                  http://www.HamiltonGenSociety.org/
                  My Web Site: http://notlimaH.tripod.com

                  ________________________________________________________________
                  YOU'RE PAYING TOO MUCH FOR THE INTERNET!
                  Juno now offers FREE Internet Access!
                  Try it today - there's no risk! For your FREE software, visit:
                  http://dl.www.juno.com/get/tagj.
                • Eb Guenther
                  Hi Larry, Jody, Thanks for the explanation. If Notetab will stand still long enough, I might get to know it all, some day . On the other hand, I still
                  Message 8 of 18 , Mar 13, 2000
                  • 0 Attachment
                    Hi Larry, Jody,

                    Thanks for the explanation.

                    If Notetab will stand still long enough,
                    I might get to know it all, some day <grin>.

                    On the other hand, I still have a wish list.

                    One of which is:

                    ^$GetListDelimter(array)$

                    Suppose you write a generic script to process an array,
                    and that script uses the array (or a copy) as a prompt
                    string in a wizard.

                    Then the delimiter, whatever it is (default, "^P", "|",
                    or even some html construct), will have to be changed
                    to "|" for the prompt.

                    How can the clip do this if it doesn't know what the actual
                    delimiter is? Or am I missing something? One can do this
                    by copying the array one element at a time, but suppose the
                    array has 10000 elements?

                    I'd like to be able to do:

                    ^!Set %delim%=^$GetListDelimiter(^%InStr%)$
                    ^!Set %PromptStr%=^$StrReplace("^%delim";"|";"^%InStr%";F;F)$


                    Cheers,


                    Eb
                    Note: Everything outside of my PGP signature is a forgery.
                    What? no PGP signature? Then the whole message is forged!
                  • Lawrence M Hamilton, Jr.
                    Hi Eb, ... The only way for a clip to know what delimiter to use is for you to tell it what the delimiter is in the file you are working with. You can set up a
                    Message 9 of 18 , Mar 13, 2000
                    • 0 Attachment
                      Hi Eb,

                      On Mon, 13 Mar 2000 09:54:56 -0600 Eb Guenther <ebg@...> writes:
                      > Hi Larry, Jody,
                      > On the other hand, I still have a wish list.
                      >
                      > One of which is:
                      >
                      > ^$GetListDelimter(array)$
                      >
                      > Suppose you write a generic script to process an array,
                      > and that script uses the array (or a copy) as a prompt
                      > string in a wizard.
                      >
                      > Then the delimiter, whatever it is (default, "^P", "|",
                      > or even some html construct), will have to be changed
                      > to "|" for the prompt.
                      >
                      > How can the clip do this if it doesn't know what the actual
                      > delimiter is? Or am I missing something? One can do this
                      > by copying the array one element at a time, but suppose the
                      > array has 10000 elements?

                      The only way for a clip to know what delimiter to use is for you to tell
                      it what the delimiter is in the file you are working with.

                      You can set up a selection box, so that you can have a choice of what
                      kind of delimiter you are working with. NoteTab starts with a default of
                      ";" (semi-colon).

                      For Example:

                      ;Prompt user for field delimiter used in document (the sample file
                      Data.txt uses tabs)
                      ^!SetDelimiter ^?[(6;T=C)Field
                      Delimiter==_Tab^=^t|Comma^=,|Semi-colon^=;|Equal
                      sign^==|SDF^="";""|VBar^="|"|Tilde^=~|None^=]

                      As for an array with 10,000 elements it is not really that hard.

                      The example I have is a file of 1500 people read into the first array as
                      a series of lines. Each line is then read, and each line can then have up
                      to 8 elements. In may case this has between 10,500 and 12,000 elements.
                      This is a way to give two-dimensional array fucntionality in NoteTab.

                      It also depends if the source of the Array is a text file or files in a
                      directory.

                      The following example will give you a listing of all text files in the
                      directory, sorted by name.

                      ^!SetListDelimiter=|
                      ^!SetArray %Files%=^$GetFiles("C:\My Documents";*.txt;NAME)$
                      ^!Info Files = ^%Files%

                      Above, the $GetFiles$ reads all the files with the *.txt extension, and
                      the SetArray command puts them into the array.

                      With a large text file that had all uniques elements between each
                      delimiter, say a list of 10,000 icons, you could read the whole thing
                      into an array with one command.

                      ^!SetListDelimiter=| (or whatever, ignore if use ";" for delimiter)
                      ; The variable file could also be the full path and filename a a
                      partivular file.
                      ^!SetArray %All%=^$GetFileText(^%file%)$

                      To learn the number of elements in the file just do:

                      ^!Info ^%All0%

                      The 0th (zeroth) element in NoteTab, stores the number of items in the
                      array, and could be say 10,001, or whatever the actual number is. If you
                      did not know what was in a particular array item, you could then call it
                      up to see with an Info command, or you could use a looping structure to
                      go through all items in the array. Of course, the larger the array, that
                      longer it will take.

                      I hope this helps.


                      Larry Hamilton, Jr. lmhamilton@...
                      Hamilton National Genealogical Society, Inc.
                      http://www.HamiltonGenSociety.org/
                      My Web Site: http://notlimaH.tripod.com

                      ________________________________________________________________
                      YOU'RE PAYING TOO MUCH FOR THE INTERNET!
                      Juno now offers FREE Internet Access!
                      Try it today - there's no risk! For your FREE software, visit:
                      http://dl.www.juno.com/get/tagj.
                    • Eb Guenther
                      Hi Larry, Thanks for the reply. ... Of course! I didn t see the forrest for the trees. It s not an array, until you know what the delimiter is! Thanks for the
                      Message 10 of 18 , Mar 14, 2000
                      • 0 Attachment
                        Hi Larry,

                        Thanks for the reply.

                        >The only way for a clip to know what delimiter to use is for you to tell
                        >it what the delimiter is in the file you are working with.

                        Of course! I didn't see the forrest for the trees.
                        It's not an array, until you know what the delimiter is!


                        Thanks for the hammer blow to the head <g>.

                        Eb
                      • Lawrence M Hamilton, Jr.
                        Hi Eb, ... Glad to help .... As long as I don t have to get a new hammer. Larry Hamilton, Jr. lmhamilton@juno.com Hamilton National Genealogical
                        Message 11 of 18 , Mar 15, 2000
                        • 0 Attachment
                          Hi Eb,

                          On Tue, 14 Mar 2000 17:59:57 -0600 Eb Guenther <ebg@...> writes:
                          > Of course! I didn't see the forrest for the trees.
                          > It's not an array, until you know what the delimiter is!

                          Glad to help .... As long as I don't have to get a new hammer. <g>


                          Larry Hamilton, Jr. lmhamilton@...
                          Hamilton National Genealogical Society, Inc.
                          http://www.HamiltonGenSociety.org/
                          My Web Site: http://notlimaH.tripod.com

                          ________________________________________________________________
                          YOU'RE PAYING TOO MUCH FOR THE INTERNET!
                          Juno now offers FREE Internet Access!
                          Try it today - there's no risk! For your FREE software, visit:
                          http://dl.www.juno.com/get/tagj.
                        Your message has been successfully submitted and would be delivered to recipients shortly.