Hey List:

We have dealt with this question here at NCOL, and one of our developers
thought the list might benefit from our musings on this stuff.

tks,
Ian

------------------------------

We've attached a couple of files to illustrate some points.  The first tml
(remove_blank_elements.tml) should produce what you are looking for. It
takes an array that includes blank values and assigns only the non-blanks to
a set of sequential variables. The @NEXTVAL tag is great for this because it
increments the variable you give it and returns the next value, negating the
need for an @ASSIGN & @CALC

A potential pitfall is using an @DELROWS in an @ROWS loop as showed in a
couple of the previously posted suggestions. The problem is doing more than
one @DELROWS in the middle iterations of a loop. The arraytest.taf got
around this by using the @DISTINCT to ensure there was only one empty value.
This however would remove all duplicate values in the array and sometimes
the duplicate values may be needed. For example, in the business card
application, an address in New York, New York would remove one too many "New
York"s. If you need to delete multiple values in an array based upon some
criteria and you are going to loop through the array to determine that, read
on...

The second file (bad_delrows.taf) demonstrates why (in our opinion) one
should never do a @DELROWS within an @ROWS loop.

Note: the same argument applies to a @FOR loop where the STEP is a positive
value.

What this file (bad_delrows.taf) does is create an array with values of A
through L. It then does a @ROWS loop. In each iteration, it outputs the
array in a table with the row numbers and the values. For the first 5
iterations, it does a @DELROWS on the @CURROW element. So in iteration 1,
row 1 is deleted, iteration 2 row 2 is deleted, etc.

Now, one might assume that this would mean A is deleted in the first
iteration and B in the second, etc.

This is not the case.

It has been our experience that a @DELROWS happens immediately. This can be
seen from the result of the @NUMROWS that was put in each iteration. The
result actually is that in the first iteration, A is deleted because it is
in row 1. This moves B to row 1.  In other words, in iteration 2, C is in
row 2 and B is never evaluated (take note of what position each letter is in
during each iteration).

Another problem with this approach: the @ROWS loop sets the number of
iterations only once. This can be seen by comparing the displayed
"Iteration" with the "Numrows in letter array" In this example if one were
to try an @DELROWS in iteration 10, no rows would be deleted because row 10
does not exist. If one tries to do an assign
in row 10 they will get an error because it is out of the array bounds.

Here are two solutions that avoid potential problems with deleting multiple
rows in a loop

1) Use a for loop but step through it backwards i.e.

<@FOR START="<@NUMROWS ARRAY='arrayname'>" STOP="1" STEP="-1">
        <@IF delete condition>
                <@DELROWS ARRAY="arrayname" POSITION="<@CURROW>">
        </@IF>
</@FOR>

This way you will always get the element you think you are getting because
removing row 10 does not change the position of row 9;

or

2) A second approach is to collect the rows you don't want to delete in
another array and then reassign the original with the new

<@ROWS ARRAY="arrayname">
        <@IF keep condition>
                <@ADDROWS ARRAY="newarrayname" VALUE="<@VAR arrayname[<@CURROW>,*]">
        </@IF>
</@ROWS>
<@ASSIGN arrayname <@VAR newarrayname>>

Hope this helps.

-----Original Message-----
From: Rick Sanders [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 27, 2004 3:22 PM
To: [EMAIL PROTECTED]
Subject: Re: Witango-Talk: ARRAY?? SOLUTION!!!


Hey Webdude,

I totally understand what you need. I've done this before.

Here's the taf with the code on how to do it.

Also, follow this link to see the results:
www.webenergy-sw.com/arraytest.taf

Rick Sanders
Vice President of I.T.
Webenergy-Icantec
Kitchener - Waterloo:(519) 741-2117
Montreal: (514) 808-0788
www.webenergy-sw.com
www.icantec.ca

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 27, 2004 2:11 PM
Subject: RE: Witango-Talk: ARRAY??


> Hi Gene and Dave,
>
> Thanks for the snips. They both work well. Unfortunately, I already
> have gotten this far. I understand how to assign and filter arrays.
>
> Maybe I should explain myself more fully...
>
> It's not the values I am concerned about, but the naming of
> individual variables in ascending order. I need the final result
> taken out of the array and put into individual variables named
> whatever1, whatever2, whatever3 and so on with no variables being
> empty. So in your example. I would nee variables with no null
> variables named spaced1, spaced2 spaced3 and so on.
>
> Example
>
> (original array)
> A (row1)
> B (row2)
> C (row3)
>     (row4)
>     (row5)
> D (row6)
> E (row7)
>     (row8)
> F (row9)
>     (row10)
> G (row11)
> H (row12)
>
> (what I need)
> <@ASSIGN spaced1 "A">
> <@ASSIGN spaced2 "B">
> <@ASSIGN spaced3 "C">
> <@ASSIGN spaced4 "D">
> <@ASSIGN spaced5 "E">
> <@ASSIGN spaced6 "F">
> <@ASSIGN spaced7 "G">
> <@ASSIGN spaced8 "H">
>
> The reason I need these variables named this way is because I am
> going to pass them as hidden arguments to an ASP program that writes
> out a business card. Now it would look funny if the cards had blank
> lines in them. Yet I need to name the cells in Acrobat specifically
> for each line on the card. So if a person wants their name, address
> and email but not there phone or fax, the args passed would go to the
> top cells.
>
> Business Card Cells on original card
>
> ____Name_________(Named spaced1)
> _____Address1_____(Named spaced2)
> _____Address2_____(Named spaced3)
> _____City, State Zip_ (Named spaced4)
> _____phone________(Named spaced5)
> _____fax__________(Named spaced6)
> _____email_________(Named spaced7)
> _____cell__________(Named spaced8)
> _____route________(Named spaced9)
> _____whatever_____(Named spaced10)
>
> would turn into...
> ____Name__________(Named spaced1)
> ______Address1_____(Named spaced2)
> ______Address2_____(Named spaced3)
> _____City, State Zip__(Named spaced4)
> ______email________(Named spaced5)
> ______(blank)_______(Named spaced6)
> ______(blank)_______(Named spaced7)
> ______(blank)_______(Named spaced8)
> ______(blank)_______(Named spaced9)
> ______(blank)_______(Named spaced10)
>
> Is this making sense???
>
>
>
>
>
>
>
> >Another way to do the same thing would be to use the filter tag:
> >
> ><@Assign Local$SpacedArray <@ARRAY VALUE="A;B;C; ; ;D;E; ;F; ;G;H;">>
> >Spaced Array Begins as = <@Var Local$SpacedArray><p>
> ><@Assign local$SpacedArray <@filter array=local$SpacedArray
> >expr="len(<@trim str='#1'>)">>
> >Spaced Array now = <@Var Local$SpacedArray><p>
> >
> >Dave Shelley
> >
> >-----Original Message-----
> >From: Wolf, Gene [mailto:[EMAIL PROTECTED]
> >Sent: Tuesday, July 27, 2004 1:05 PM
> >To: [EMAIL PROTECTED]
> >Subject: RE: Witango-Talk: ARRAY??
> >
> >    Sure. Here's sample code. I've tested it, it works.
> >
> ><@Assign Local$SpacedArray <@ARRAY VALUE="A;B;C; ; ;D;E; ;F; ;G;H;">>
> >
> >Spaced Array Begins as = <@Var Local$SpacedArray><p>
> ><@Assign Local$RowCount <@Numrows Array=Local$SpacedArray>>
> ><@Assign Local$Ptr 1>
> >
> ><@FOR START="1" STOP="<@Var Local$RowCount>">
> > <@IFEMPTY VALUE="<@Trim Str=<@Var
> >Local$SpacedArray[<@Currow>,1]>>">
> > <@ELSE>
> > <@Assign Local$SpacedArray[<@Var Local$Ptr>,1] <@Var
> >Local$SpacedArray[<@Currow>,1]>>
> > <@IF EXPR="<@Currow>!=<@Var Local$Ptr>">
> > <@Assign Local$SpacedArray[<@Currow>,1] ' '>
> > </@IF>
> > <@Assign Local$Ptr <@Calc EXPR="<@Var Local$Ptr>+1">>
> > </@IF>
> ></@FOR>
> >Spaced Array now = <@Var Local$SpacedArray><p>
> ><@Assign Local$Ptr <@Calc EXPR="<@Var Local$Ptr>">>
> >
> >
> ><@Comment>Delete Remaining blank rows in the Array</@Comment>
> ><@FOR START="<@Var Local$Ptr>" STOP="<@Var Local$RowCount>">
> > <@Delrows Array=Local$SpacedArray>
> ></@FOR>
> >Spaced Array now = <@Var Local$SpacedArray><p>
> >
> >
> >Hope this helps!
> >
> >
> >-----Original Message-----
> >From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> >Sent: Tuesday, July 27, 2004 9:50 AM
> >To: [EMAIL PROTECTED]
> >Subject: RE: Witango-Talk: ARRAY??
> >
> >
> >Hey Gene,
> >
> >I have been trying to wrap my arms around this one. Do you have a
> >simple example you could show/send me? For some reason the second
> >loop never counts.
> >
> >Also,
> >
> >is it possible to do this using the <@for> tag?
> >
> >Thanks for any help.
> >
> >>May I suggest a solution? Introduce another variable called Ptr.
> >>Initialize it to one. Walk through your loop testing each element
> >>for values. For examining array fields for nulls I typically use
> >><@Trim Str="<@Var...
> >>
> >>     Now, if you do NOT find the array element empty increment Ptr by
> >>one. As long as the array elements have valid values Ptr will keep
> >>pace with your look counter. When the first empty spot is detected
> >>both counters will be the same.
> >>
> >>     At the bottom of the loop you test to see the array element
> >>pointed to by your loop index is empty. If not, test to see if loop
> >>index and Ptr are the same. If so, do nothing. If not, assign the
> >>element pointed at by your loop variable to the location pointed at
> >>by Ptr and empty the element pointed at by your loop counter. Then
> >>increment your loop counter and Ptr. When you run across an empty
> >>cell, with your loop counter, you do not increment Ptr.
> >>
> >>     This will collapse all of the empty space out of your array and
> >>condense it at the end of your array.
> >>
> >>     It is complicated to explain but very easy to do. A small loop
> >>and a couple of if statements.
> >>
> >>-----Original Message-----
> >>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> >>Sent: Wednesday, July 21, 2004 4:20 PM
> >>To: [EMAIL PROTECTED]
> >>Subject: Witango-Talk: ARRAY??
> >>
> >>
> >>Okay,
> >>
> >>I'm tired and crabby and need help. This should be simple, but for
> >>some reason, I am just not seeing it.
> >>
> >>I have variables that I am populating with small amounts of text.
> >>They are named ...
> >>
> >><@VAR lcell1> = test1
> >><@VAR lcell2> =
> >><@VAR lcell3> = test3
> >><@VAR lcell4> = test4
> >>etc.
> >>etc.
> >>etc.
> >>
> >>Let's just stop at 4 for now to keep this simple (simple is good! Good
> >simple)
> >>
> >>Now I created a loop and a counter that counts up to 4 and I have
> >>added this in the loop...
> >>
> >><@IFEMPTY <@VAR 'lcell<@VAR l_counter>'>>
> >><@ELSE>
> >><@ASSIGN NAME="llcell<@VAR l_counter>" VALUE="<@VAR 'lcell<@VAR
> >l_counter>'>">
> >></@IF>
> >>
> >>And when I display the results I can see the values correctly. It is
> >>working as expected BUT I would like to skip the counter on every
> >><@VAR lcell that is empty. I other words, If <@VAR lcell2> is empty,
> >>move the values from <@VAR lcell3> into <@VAR lcell2> and also move
> >>the values from <@VAR lcell4> into <@VAR lcell3>. Is this making
> >>sense? I would like to get all the variables named 1, 2, 3, 4 etc.
> >>with no empty variables between.
> >>
> >>The final result should be a list of numbered variable that contain
> >>no empty variables or empty variables in the end...
> >>
> >>Original Variables...
> >>
> >><@VAR lcell1> = test1
> >><@VAR lcell2> =
> >><@VAR lcell3> = test3
> >><@VAR lcell4> = test4
> >>
> >>Modified Variables
> >>
> >  ><@VAR llcell1> = test1
> >><@VAR llcell2> = test3
> >><@VAR llcell3> = test4
> >  ><@VAR llcell4> =
> >>
> >>Thanks
> >>
> >>There's gotta be an easy way to do this
> >>
> >>_______________________________________________________________________
> >_
> >>TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >>_______________________________________________________________________
> >_
> >>TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >
> >________________________________________________________________________
> >TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >________________________________________________________________________
> >TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
> >
> >________________________________________________________________________
> >TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
>
> ________________________________________________________________________
> TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
>
________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

________________________________________________________________________
TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf

Attachment: remove_blank_elements.tml
Description: Binary data

Attachment: bad_delrows.tml
Description: Binary data

Reply via email to