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

Newbie seeks help with array processing

Expand Messages
  • Ed Wilson
    Can anyone point me to resources/advice on use of arrays in NoteTab? And then string concatenation? Ed
    Message 1 of 9 , Mar 28, 2008
      Can anyone point me to resources/advice on use of arrays in NoteTab? And then string concatenation? Ed
    • dracorat
      Here is a program I wrote that takes apart a string and then creates an XML document based on the results. I hope it has the info you need. If not, ask for
      Message 2 of 9 , Mar 28, 2008
        Here is a program I wrote that takes apart a string and then creates
        an XML document based on the results.

        I hope it has the info you need. If not, ask for more.

        The source data looks like this btw:
        36094 PERSON NAME 3515 PENNYROYAL LN 80906 $93,147.86 Withdrawn
        36630 ANOTHER NAME 1103 N CHELTON RD 80909 $93,460.75 Withdrawn
        37654 AND YET ANOTHER 537 HOLLY DR 80911 $88,991.70 Redeemed by Owner

        Now, the clip:
        ^!SET %DocIndex%=^$GetDocIndex$
        ^!SET %FileCheck%=^$GetFiles("c:\";Transactional.XML)$
        ^!SetWordWrap OFF
        ^!If "^%FileCheck%" > "" NEXT ELSE CreateFile
        ^!Open "C:\Transactional.XML" /J=-1
        ^!SetWordWrap OFF
        ^!Goto BeginWork
        :CreateFile
        ^!TOOLBAR New Document
        ^!SetWordWrap OFF
        ^!Save AS "C:\Transactional.XML"

        :BeginWork
        ^!SetDocIndex ^%DocIndex%
        ^!Jump DOC_START
        ^!Set %TotalLines%=^$GetLineCount$
        ^!Set %CurrentLine%=0

        :WorkLoop
        ^!Select LINE
        ^!Find
        "\w*(\d+)\s(\D+)((?:.(?!80\d{3}))+.)(80\d{3})[\w\s\d\.\,\-\'\#]*(\$[\d\.\,]+)\s*(\w*)"
        HRS
        ^!SetArray %Data%=^$GetReSubStrings$
        ^!IF ^%Data0% < 6 BADROW
        ^!SET %Data1%=^$StrReplace("&";"&";^%Data1%;False;False)$
        ^!SET %Data2%=^$StrReplace("&";"&";^%Data2%;False;False)$
        ^!SET %Data3%=^$StrReplace("&";"&";^%Data3%;False;False)$
        ^!SET %Data4%=^$StrReplace("&";"&";^%Data4%;False;False)$
        ^!SET %Data5%=^$StrReplace("&";"&";^%Data5%;False;False)$
        ^!SET %Data6%=^$StrReplace("&";"&";^%Data6%;False;False)$
        ^!Open "C:\Transactional.XML" /J=-1
        ^!InsertText
        "<Transaction><SiteID>^%Data1%</SiteID><Name>^%Data2%</Name><Address>^%Data3%</Address><ZIP>^%Data4</ZIP><Valuation>^%Data5%</Valuation><Status>^%Data6%</Status></Transaction>^P"
        ^!Save AS "C:\Transactional.XML"
        ^!Goto PostProcessing

        :BadRow
        ^!Prompt "The Highlighted Row Could Not Be Processed"

        :PostProcessing
        ^!SetDocIndex ^%DocIndex%
        ^!Set %CurrentLine%="^$Calc(^%CurrentLine%+1)$"
        ^!If ^%CurrentLine%=^%TotalLines% FinishOut
        ^!Select 0
        ^!Jump +1
        ^!Goto WorkLoop

        :FinishOut
        ^!Select 0
        ^!Jump DOC_END
        ^!Open "C:\Transactional.XML" /J=-1



        Inside the WorkLoop has most of what you're asking for I believe but
        the whole program is included so you can test with it.

        Enjoy.

        --Keith


        --- In ntb-clips@yahoogroups.com, Ed Wilson <eddwilson@...> wrote:
        >
        > Can anyone point me to resources/advice on use of arrays in NoteTab?
        And then string concatenation? Ed
        >
      • Ed Wilson
        Thanks Keith. I ll take it apart tomorrow. Ed
        Message 3 of 9 , Mar 28, 2008
          Thanks Keith. I'll take it apart tomorrow. Ed
        • Don - HtmlFixIt.com
          you did read help under clip programming variables? ^!SetArray %VariableName%=ArrayData (added in v4.6) Similar to the ^!Set command but creates an array from
          Message 4 of 9 , Mar 28, 2008
            you did read help under clip programming variables?

            ^!SetArray %VariableName%=ArrayData (added in v4.6)

            Similar to the ^!Set command but creates an array from the data assigned
            to it. By default, the data delimiter is a plain semi-colon (;), or a
            semi-colon and double-quotes separating each item. You can change the
            default delimiter with the command ^!SetListDelimiter (see below).
            During the assignment, the individual items from the ArrayData are each
            stored in a new variable with the same name as the base variable plus an
            index number reflecting their corresponding position. The variable at
            index 0 has a special purpose as it stores the actual number of items
            contained in the array. You can change the values of the individual
            indexed items by using the ^!Set, ^!Inc, ^!Dec commands, and the changes
            are reflected in the base variable. If you assign an empty value to an
            array variable, or use the ^!Set command to assign a new value to it,
            the array is automatically removed from memory.



            Examples:

            ^!SetArray %Array%="Value 1";"Value 2";"Value 3"

            The above instruction will create four new variables:

            ^%Array0% = 3

            ^%Array1% = Value 1

            ^%Array2% = Value 2

            ^%Array3% = Value 3

            If we assign a new value to the second item, as follows:

            ^!Set %Array2%=New Value

            then accessing the base variable ^%Array% will return:

            "Value 1";"New Value";"Value 3"

            The following assignment will destroy the array, and only the base
            variable will be preserved with the newly assigned value:

            ^!Set %Array%=Another Value
          • buralex@gmail.com
            Don - HtmlFixIt.com said on Mar 28, 2008 20:45 ... The one thing I d add to Don s summary is how to process elements of an array in a
            Message 5 of 9 , Mar 28, 2008
              "Don - HtmlFixIt.com" <don@...> said on Mar 28, 2008 20:45
              -0400 (in part):
              > ^!SetArray %VariableName%=ArrayData (added in v4.6)
              The one thing I'd add to Don's summary is how to process elements of an
              array in a loop.
              For some reason it took me a long time to understand how the syntax for
              the key statement works:
              ^!set %thisVal%=^%theArray^%i%%

              As in:

              ^!SetArray %theArray%="Value 1";"Value 2";"Value 3"
              ^!set %i%=0
              :loop
              ^!inc %i%
              ^!if ^%i% >^%theArray0% alldone
              ^!set %thisVal%=^%theArray^%i%%
              ; -- do something ---
              ^!info ^%i% = ^%thisVal%
              ^!goto loop
              :alldone

              Regards ... Alec -- buralex-gmail
              --



              [Non-text portions of this message have been removed]
            • Ed Wilson
              Yes, Don, I did read the help, but Alec s example includes the one line ^!set %thisVal%=^%theArray^%i%% which illustrates my problem - embedding the index as
              Message 6 of 9 , Mar 29, 2008
                Yes, Don, I did read the help, but Alec's example includes the one line

                ^!set %thisVal%=^%theArray^%i%%

                which illustrates my problem - embedding the index as part of the name of the array item. All I'm after is a few examples to dip into as I get used to the conventions.

                Ed
              • Don - HtmlFixIt.com
                ... Yep, this line is key. You can just use the array item as well directly without setting something else equal to it. Also the first element in the array is
                Message 7 of 9 , Mar 29, 2008
                  Ed Wilson wrote:
                  > Yes, Don, I did read the help, but Alec's example includes the one line
                  >
                  > ^!set %thisVal%=^%theArray^%i%%
                  Yep, this line is key. You can just use the array item as well directly
                  without setting something else equal to it.

                  Also the first element in the array is the number of elements in it, so
                  you can use it to dec (de-increment) through the array or to limit the
                  inc (increment) to the number of elements in the array.

                  Help isn't always easy to follow, so just checking :-)
                • Alec Burgess
                  Ed: If you haven t found them already two clips in the SampleCode library distributed with Notetab illustrate the ^%theArray^%i%% method of accessing an
                  Message 8 of 9 , Mar 29, 2008
                    Ed:
                    If you haven't found them already two clips in the "SampleCode"
                    library distributed with Notetab illustrate the ^%theArray^%i%% method
                    of accessing an array element by index number. In most programming
                    languages it would be something like: theArray(i) or theArray[i].
                    see SetArray demo 1 and SetArray demo 3.

                    In your original question you also asked
                    > And then string concatenation?
                    Have you figured that out yet? Basically its as simple as:
                    ^!set %varA%=something
                    ^!set %varB%=something else
                    then
                    ^!set %varC%=^%varA%^%varB%
                    which results in varC having the value: "somethingsomething else"

                    btw: for reasons I'm trying to check with my ISP email from your
                    address "AT postmaster DOT co DOT uk" is getting bounced by my ISP
                    aci.on.ca. If you want to reply could you possibly reply from the
                    yahoo groups web interface or I may not see it. (Obviously dracorat
                    (Keith) and Don are seeing your messages with no problems)

                    Just curious - have you had any other problems with having your email
                    get through to end-recipients.
                    Regards ... Alec
                    --
                    On Sat, Mar 29, 2008 at 1:52 PM, Ed Wilson <eddwilson@...> wrote:

                    > Yes, Don, I did read the help, but Alec's example includes the one line
                    >
                    > ^!set %thisVal%=^%theArray^%i%%
                    >
                    > which illustrates my problem - embedding the index as part of the name of
                    > the array item. All I'm after is a few examples to dip into as I get used to
                    > the conventions.
                    >
                    > Ed
                  • Don - HtmlFixIt.com
                    ... And depending what you want, if you just use ^%varC% it is the values in the array with the delimiter ... in essence pre-concatenated if you will. example:
                    Message 9 of 9 , Mar 29, 2008
                      Alec Burgess wrote:
                      > Ed:
                      > If you haven't found them already two clips in the "SampleCode"
                      > library distributed with Notetab illustrate the ^%theArray^%i%% method
                      > of accessing an array element by index number. In most programming
                      > languages it would be something like: theArray(i) or theArray[i].
                      > see SetArray demo 1 and SetArray demo 3.
                      >
                      > In your original question you also asked
                      >> And then string concatenation?
                      > Have you figured that out yet? Basically its as simple as:
                      > ^!set %varA%=something
                      > ^!set %varB%=something else
                      > then
                      > ^!set %varC%=^%varA%^%varB%
                      > which results in varC having the value: "somethingsomething else"

                      And depending what you want, if you just use ^%varC% it is the values in
                      the array with the delimiter ... in essence pre-concatenated if you will.

                      example:
                      ^!SetArray %daysinmonth%=31;28;31;30;31;30;31;31;30;31;30;31
                      ^!Info [C] x^%daysinmonth%x
                    Your message has been successfully submitted and would be delivered to recipients shortly.