Array question
John Esak
john at valar.com
Tue Mar 9 15:15:55 PST 2010
Hi Tom,
You are right on it... Just a little way to go...
First a quick comment on your looping code. The END will never happen. You
can remove that. The loop ends if you don't find a record (EOF), or if the
lookup key doesn't match field 1, or if your loop boundary is reached. One
of these 3 things will eventually end the loop. It will never get to that
END in any way.
Okay, I think you bought the CD's and there are a couple movies about this
exact scenario you want. Just put "array" in the search criteria and the
right movies will pop up and you can hit enter on the one you want. If the
wrong CD of the set is not in the drive it will prompt you to put it in and
then take you the movie.
So, if what I put next doesn't get your brain around it... Do that. (Hell,
didn't you even *win* that copy of the Tutorial CD's... I remember you won
something! :-) Maybe it's why you don't value it enough to go right to it
for an answer like this. :-) Okay, commercial over... :-)
When you overlay an array on a lookup, you are setting the beginning field
with the m value. By the way, it can't be a variable it has to be a
"legitimate field number in the lookup file", so it must look something like
this:
dim array[24]:lookup-alias(10)
That would start this 24 element array at field 10 on the lookup record.
You can put this this DIM anywhere ahead of the lookup or any use of the
fields in the array, such as array[x]. Also, don't bother to try and set
the lengths and edits of this array. It will simply be congruent with the
fields in the lookup file. Each field in the array takes on those
characteristics.
The moment you actually do the lookup and find a record, this array becomes
"filled". Referencing any element in it is just like referencing the field
by using the lookup-alias and a field. So
Array["1"] and lookup-alias(10) are exactly the same value.
Now, just by DIMensioning this array and performing the lookup, you've
filled the array with the 24 values from the lookup file... Now you want to
get them into sequential variables in this file... Probably to display on a
screen or a report. The simplest thing to do is DIM another array of 24
fields and overlay it on the starting variable. You would do something like
this:
Dim scr_vars[24](len,edit):aa
If all the fields are the same size, it's easy to just specify the length
and edit one time. If not, you could do each one individually or just pick a
length you know will work for every one of the 24 elements. Anyway, I
digress. Now that you have this array in your table, you have to fill it
with the values from the overlaid on the lookup array. You can most easily
do this with another quick loop.
Fillit if:
then: declare ptr(2,.0); ptr="1"
Lp_fill if: ptr gt "24"
then: return
then: scr_vars[ptr]=array[ptr]; ptr=ptr + "1"; goto lp_fill
After hitting this "fillit" subroutine you can use the variables aa-ax or
the scr_vars[m] values wherever you want... In the table, on the screen or a
report. If I were you at the top of the prc table, as you hit each new
record, I would clear the scr_vars array. "clear scr_vars".
DO NOT EVER CLEAR AN ARRAY OVERLAID ON A LOOKUP FILE!!!!
Why? Because, obviously, the fields on that record will be instantly
cleared. Of course there could be a time when you *want* to do this... But
that's your call. Be very careful and understand that the lookup fields and
the array are exactly the same. What you do to one, reflects in the other.
They are simply different ways of pointing to that field. The exact same
WARNING applies if you overlay an array over the real fields in the file on
which you're standing.
DIM array[24]:15
Don't be clearing this array or doing anything to these array elements
unless you really want to alter the values in the fields of the current
record.
That's it very easy.
John
> -----Original Message-----
> From: filepro-list-bounces+john=valar.com at lists.celestial.com
> [mailto:filepro-list-bounces+john=valar.com at lists.celestial.co
m] On Behalf Of Aldridge, Inc.
> Sent: Tuesday, March 09, 2010 4:53 PM
> To: filepro-list at lists.celestial.com
> Subject: Array question
>
> So, I do this kind of thing rather often:
>
> dim scremp(7)(26,uplow):ga
> pshift:
> ::lookup scremps k=ka i=A -nx:
> loop6:not scremps:return:
> :scremps(1) ne 1:return:
> :zz ge "5":return:
> ::scremp(zz)=number{"." <scremps(6) <scremps(5):
> ::zz=zz+"1"; number=number+"1"; getnext scremps; goto loop6:
> ::end:
>
> But in the present case, I want to fill 24 dummy fields, say
> aa-ax with
> the contents of 24 sequential fields in a lookup file beginning with
> field 50 there.
>
> In help, I see this:
>
> "DIM array(n):lookup(m)
>
> Example: DIM place(2):CLIENTS(3) 'A 2 field array
> taken from a lookup named CLIENTS starting
> at its field 3."
>
> Is that a good way to accomplish this? If yes, but where in
> this example
> would I tell the local array to begin, i.e. aa?
>
> I'm missing some level of understanding here and would
> appreciate some
> insights or suggestions. Thanks
>
> Tom Aldridge
> _______________________________________________
> Filepro-list mailing list
> Filepro-list at lists.celestial.com
> http://mailman.celestial.com/mailman/listinfo/filepro-list
>
More information about the Filepro-list
mailing list