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

array ... can you append to an array?

Expand Messages
  • Don Passenger
    ^!SetArray %array%=a;b;c but then I want to add d ... how do I do it?
    Message 1 of 10 , Nov 4, 2003
      ^!SetArray %array%=a;b;c

      but then I want to add d ... how do I do it?
    • Alan C.
      ... i think there s no way to do it directly (remember, append is unlike set in that it won t trigger a function) append seems to need some sort of a variable
      Message 2 of 10 , Nov 4, 2003
        On Tue, 04 Nov 2003 23:07:49 -0500, Don Passenger wrote:
        >�^!SetArray %array%=a;b;c
        >
        >�but then I want to add d ... how do I do it?

        i think there's no way to do it directly (remember, append is unlike set in that it won't trigger a function) append seems to need some sort of a variable on the right side of the =

        an array works (as some sort of a variable) on the right side of the = as can seen below

        but i appened onto an empty variable then discarded that temp(orary)

        but the next accomplishes the feat by temporarily put the array into a variable, use append, then reset the array (setarray again)

        H="junk"
        ^!ClearVariable %temp%
        ^!SetArray %array%=a;b;c
        ^!Info ^%array%
        ^!Append %temp%=^%array%;d
        ^!SetArray %array%=^%temp%
        ^!Info ^%array%
        ^!ClearVariable %temp%

        -------------------------------------------
      • loro
        ... I don t think you need the temporary variable. It seems that ^!Append used with an array automatically converts it to a normal variable. Don t find
        Message 3 of 10 , Nov 4, 2003
          Alan C. wrote:
          >but the next accomplishes the feat by temporarily put the array into a variable, use append, then reset the array (setarray again)
          >
          >H="junk"
          >^!ClearVariable %temp%
          >^!SetArray %array%=a;b;c
          >^!Info ^%array%
          >^!Append %temp%=^%array%;d
          >^!SetArray %array%=^%temp%
          >^!Info ^%array%
          >^!ClearVariable %temp%

          I don't think you need the temporary variable. It seems that ^!Append used with an array automatically converts it to a normal variable. Don't find anything on it in Help so don't take my word for it but it seems to work.

          ^!SetArray %arr%=a;b;c
          ^!Info ^%arr%
          ^!Append %arr%=;d;e
          ^!Info ^%arr%
          ^!SetArray %arr%=^%arr%
          ^!Info ^%arr5%

          Lotta
        • Alan C.
          ... [ . . ] ... well, perhaps i wasn t specific enough i d wanted to insure also that the %arr0% would update as well (the count of items) which, what i did
          Message 4 of 10 , Nov 4, 2003
            On Wed, 05 Nov 2003 07:34:48 +0100, loro wrote:
            >�Alan C. wrote:
            [ . . ]
            >
            >�I don't think you need the temporary variable. It seems that ^!Append used with an array automatically converts it to a normal variable. Don't find anything on it in Help so don't take my word for it but it seems to work.
            >
            >�^!SetArray %arr%=a;b;c
            >�^!Info ^%arr%
            >�^!Append %arr%=;d;e
            >�^!Info ^%arr%
            >�^!SetArray %arr%=^%arr%
            >�^!Info ^%arr5%

            well, perhaps i wasn't specific enough

            i'd wanted to insure also that the %arr0% would update as well (the count of items) which, what i did does updates it with the changed count of items.

            did you check to see if yours updates that index or count of items?

            --
            Alan.
          • Don Passenger
            I feel better to see some discussion on this. Here is what I did last night: ^!SetArray %testarray%=^%testarray%;^%Place% As I ran that as a loop it appended
            Message 5 of 10 , Nov 5, 2003
              I feel better to see some discussion on this. Here is what I did last
              night:
              ^!SetArray %testarray%=^%testarray%;^%Place%

              As I ran that as a loop it appended fine and updated the variable
              %testarray0% to the proper count.
              The only problem was that it put nothing in %testarray1%

              so it would look like this:
              ;value1;value2;value3;

              with nothing before the first ;

              I tried (unsucessfully so far) to build a switch ...
              if array is empty then fill in way that doesn't add the empty element
              else append to array that has a value in it

              Alan C. wrote:
              > On Wed, 05 Nov 2003 07:34:48 +0100, loro wrote:
              >
              >> Alan C. wrote:
              >
              > [ . . ]
              >
              >> I don't think you need the temporary variable. It seems that ^!Append used with an array automatically converts it to a normal variable. Don't find anything on it in Help so don't take my word for it but it seems to work.
              >>
              >> ^!SetArray %arr%=a;b;c
              >> ^!Info ^%arr%
            • BHCS
              I have another problem to solve with a csv file. I get really large files (100,000 + lines/records) periodically to massage that I do with a dbms but I think
              Message 6 of 10 , Nov 5, 2003
                I have another problem to solve with a csv file. I get really large
                files (100,000 + lines/records) periodically to massage that I do with a
                dbms but I think NTP could do it faster.

                It comes in this format:
                "field47","field46"," .... ,"field1"
                (2 contracters I hire use iPaq's while the rest use a similar app on the
                Palm - the Palms export in field1-field47 order, but the iPaqs reverse
                the field order at export -- they do it on the csv file I had questions
                about last week too???)

                I'd like a dialog that asks...
                * do I want to reverse the order
                * do I want to drop/erase any fields (using #'s to specify,
                eg: 5,9,10,30,40-44 -- using comma separated number for
                1 specific field & nn-nn for a range)
                * what path/filename to use at save
                (obviously I can use Alan's code from my earlier clip
                question for this)

                Then the rest of the clip does the work

                Also, does anyone have or seen clip code that parses a field & breaks it
                down into discreet elements, then creates new fields to store data in?
                e.g.:
                "Wiley B. Jones","123 Second St.","... --> "Wiley","B","Jones","123....
                "Nora Smith","5420 XYZ Ave."."... --> "Nora","","Smith","5420...

                Bill
              • Alan C.
                ... ; ^!Find .* , .* , ^%client% , .* , .* , .* , .* , .* RSI ; ^!Find ^%whattask% .* , .* , .* , .* , .* , .* , .* , .* RSI ; ^!Find
                Message 7 of 10 , Nov 5, 2003
                  :repeat
                  ; ^!Find "".*",".*","^%client%",".*",".*",".*",".*",".*"" RSI
                  ; ^!Find ""^%whattask%".*",".*",".*",".*",".*",".*",".*",".*"" RSI
                  ; ^!Find ""^%whattask%",".*",".*",".*",".*",".*",".*",".*"" RSI
                  ^!Find Cinco SI
                  ^!GoTo end
                  ^!IfError finish
                  ^!AppendToFile "^%path%^%scratchdoc%" ^$GetSelection$^%NL%
                  ^!Replace "^$GetSelection$" >> "^%EMPTY%" IS
                  ^!GoTo repeat
                  :finish


                  (1st of 4 find lines is the original which had been proven to work)
                  Even after fixing the regex find, I couldn't get it to find

                  Cinco fillup

                  your find line (the 2d one) was missing a comma

                  3rd find line hopefully is correct but still refused to find Cinco fillup

                  perhaps it wasn't finding anything in the source doc??

                  ^!GoTo end

                  then can visually see if it found or not. then when done testing, just do like next

                  ; ^!GoTo end

                  --
                  Alan.
                • Larry Hamilton
                  ... From Help: 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
                  Message 8 of 10 , Nov 9, 2003
                    Don Passenger wrote:
                    > I feel better to see some discussion on this. Here is what I did last
                    > night:
                    > ^!SetArray %testarray%=^%testarray%;^%Place%
                    >
                    > As I ran that as a loop it appended fine and updated the variable
                    > %testarray0% to the proper count.
                    > The only problem was that it put nothing in %testarray1%
                    >
                    > so it would look like this:
                    > ;value1;value2;value3;
                    >
                    > with nothing before the first ;
                    >
                    > I tried (unsucessfully so far) to build a switch ...
                    > if array is empty then fill in way that doesn't add the empty element
                    > else append to array that has a value in it

                    From Help:

                    "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.
                    "

                    I think what you would have to do is read the value of ^%Array0%, say 3,
                    which would indicate three items in the array.

                    What you will need to do is have a temporary Array to hold the current value
                    of the Array, then set the Array=^%TempArray%;New Information.

                    Anytime you use ^!Set or ^!SetArray, it will clear out the array.

                    It seems like I have seen this handled in a clip, but I cannot find it. I do
                    not remember what clip(s) I saw it in. I think perhaps Jody did something
                    like this in one of his clip libraries.

                    HTH,

                    Larry Hamilton
                    lmh@...
                    http://notlimah.tripod.com/
                  • funkysmama
                    Hi Don-- I m not sure this is the slickest way to solve your problem, but it works: ;CODE BEGINS HERE ^!SetArray %newArray%= ^!Set %counter%=0 ... ^!If
                    Message 9 of 10 , Nov 10, 2003
                      Hi Don--

                      I'm not sure this is the slickest way to solve your problem, but it
                      works:

                      ;CODE BEGINS HERE

                      ^!SetArray %newArray%=
                      ^!Set %counter%=0

                      :Loop
                      ^!If ^%counter%>4 Finish
                      ^!Inc %counter%
                      ^!IfTrue ^$IsEmpty(^%newArray%)$ InitializeArray ELSE AppendArray

                      :InitializeArray
                      ^!SetArray %newArray%=^%counter%
                      ^!Goto Loop

                      :AppendArray
                      ^!SetArray %newArray%=^%newArray%;^%counter%
                      ^!Goto Loop

                      :Finish
                      ^!Info newArray(0)=^%newArray0%^PnewArray=^%newArray%

                      ;CODE ENDS HERE

                      I'm not sure why, but substituting these two lines:

                      ^!IfTrue ^$IsEmpty(^%newArray%)$ ^!SetArray %newArray%=^%counter%
                      ELSE ^!SetArray %newArray%=^%newArray%;^%counter%
                      ^!Goto Loop

                      for the IfTrue and labeled sections did not work.

                      Does this help?

                      --Funky's Mama


                      --- In ntb-clips@yahoogroups.com, Don Passenger <dpasseng@i...> wrote:
                      > I feel better to see some discussion on this. Here is what I did
                      last
                      > night:
                      > ^!SetArray %testarray%=^%testarray%;^%Place%
                      >
                      > As I ran that as a loop it appended fine and updated the variable
                      > %testarray0% to the proper count.
                      > The only problem was that it put nothing in %testarray1%
                      >
                      > so it would look like this:
                      > ;value1;value2;value3;
                      >
                      > with nothing before the first ;
                      >
                      > I tried (unsucessfully so far) to build a switch ...
                      > if array is empty then fill in way that doesn't add the empty
                      element
                      > else append to array that has a value in it
                      >
                      > Alan C. wrote:
                      > > On Wed, 05 Nov 2003 07:34:48 +0100, loro wrote:
                      > >
                      > >> Alan C. wrote:
                      > >
                      > > [ . . ]
                      > >
                      > >> I don't think you need the temporary variable. It seems that ^!
                      Append used with an array automatically converts it to a normal
                      variable. Don't find anything on it in Help so don't take my word for
                      it but it seems to work.
                      > >>
                      > >> ^!SetArray %arr%=a;b;c
                      > >> ^!Info ^%arr%
                    • David Elliott
                      The simplest way to reinitialize the array status of a variable is to immediately save a variable to itself after an append. Alternatively, you can append with
                      Message 10 of 10 , Nov 10, 2003
                        The simplest way to reinitialize the array status of a variable is to
                        immediately save a variable to itself after an append.
                        Alternatively, you can append with a SetArray instead of an Append as
                        the following demonstrates:

                        Array Append Examples
                        ^!ClearVariables
                        ^!SetArray %example%="Example 1";"Example 2";"Example 3"
                        ^!Info [L]Initial Array with ^%example0% Elements^%NL%^%example%
                        ;This loses the array structure
                        ^!Append %example%=;"Example 4"
                        ^!Info [L]Array after append with ?^%example0% Elements^%NL%^%example%
                        ;This step re-establishes the array
                        ^!SetArray %example%=^%example%
                        ^!Info [L]Array after being saved into itself with ^%example0%
                        Elements^%NL%^%example%
                        ;This method doesn't lose the array structure
                        ^!SetArray %example%=^%example%;"Example 5"
                        ^!Info [L]Array using SetArray to append with ^%example0% Elements^%
                        NL%^%example%

                        Let's face it - NoteTab's array structure is pretty loosey goosey and
                        doesn't behave like arrays in other programming languages. However,
                        you can do things with the text in arrays that other languages
                        wouldn't allow.

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