Topic: Mapping Arrays To Fields

Greetings,

Is it possible to map an array to a set of fields?

I have to record a set of statuses (they are numeric) for a set of operations, each operation will have its own row in the DB.
I then have to keep a running  MIN, MAX, AVG for the last 25 tests.  When a new test is run I need to shift the values and compute
a new set of MIN, MAX, AVG for the then last 25 tests.

Now I can shift    filed25 := field24, etc down the list to shift and I can check MIN, MAX and sum up for AVG in a long set of
statements or if I can map an array I can do all in a fairly compact loop structure.  If I move field values to an array then I have to
move them back, there probable not much to be gained... just wondering if it is possible to not have to write a novel of code?

Regards,
Keith

Re: Mapping Arrays To Fields

I'm not so sure on what you really want. But here, I previously made a function involving arrays. I hope it gives you an idea to what you are looking for.

Post's attachments

Attachment icon array_func.zip 494.23 kb, 232 downloads since 2021-01-27 

brian

3 (edited by kweatherhead 2021-01-27 22:10:26)

Re: Mapping Arrays To Fields

Brian,

Thanx for your example...  I have added an example structure to help clarify what I am trying to do.

Running the initial example and selecting the "Shift" Button will show another form.  All I want to due is update fields
2 & 3.  The first field will be a read-only of the test module.  Then enter new result & date, increment count, re-compute the Min, Max, AVG.

Then shift the previous test results down one  (again I show 10 for this example, the list is actually 25) insert the new Curr Score & Date
prior to the computations.

was wondering if there was a better way than...

Prv25_Score := Prv24_Score;
Prv24_Score := Prv23_Score;
Prv23_Score := Prv22_Score;
.
.
Prv2_Score := Curr_Score;
Curr_Score :=  (Entered Value);


Also have to shift the Dates as well.

Keith

Post's attachments

Attachment icon keith_Array_Func2 (Shifting).zip 339.35 kb, 208 downloads since 2021-01-27 

4 (edited by derek 2021-01-28 01:56:57)

Re: Mapping Arrays To Fields

Hi Keith, Hi Brian,
I was having a look at your post and didn't have much success going down the array route so decided to go 'old school'.
It's not as concise as you'd want but I'd probably approach it something like the attached (I just did it for 10 inserts but the principle is the same).
It gives you the flexibility to enter operations, values and dates 'in bulk' or of entering the readings for each date and then 'rolling' the readings and dates forward.  Importantly, it allows you to amend any of the 10 values or dates and update without performing a 'roll' to correct any input errors that could have been made previously.
Note that in the example, I don't start calculating averages, minimums or maximums until I have a full set (10) of readings - not sure how you plan to do it.
Is there any reason why you can't hold the readings and dates in a 'readings' table with a relationship to an 'operations' table - then you could just show the latest 25 records from the 'readings' table but it could hold a full history of all the readings?  It would simplify lots of things.
Derek.

Post's attachments

Attachment icon Keith.zip 340.82 kb, 269 downloads since 2021-01-28 

Re: Mapping Arrays To Fields

Derek,

I am beginning to believe the more I look at this a simple row per reading and the computed fields for that row and the previous 24 might be a lot easier.  I need to keep rolling MIN, MAX & AVG for the current & 24 previous entries so that is why I was initially trying to keep it a single row in the DB but that looks to be more of a nightmare.  I know the potential client is gonna want trending on that data too so it might be better to make them single items.  I did not want everything on the input form, but in order to roll the fields even in your example they would have to be on the form, even if it could be done "hidden" they would still need to be on the form.

Back to the drawing board, but THANX for the thoughts and effort !!!

Regards,
Keith