Welcome! Log In Create A New Profile

Advanced

Modify a value on a structured array

Posted by donschwirtlich 
Modify a value on a structured array
September 27, 2018 03:48PM
I have a structured array, i loop through, insert starting values into the fields, then I want to loop back through the array, and modify a specific line of that array. As in

ArrayModify(OrdLine[nsub].FieldIWantChanged) or ArrayChange.... or do I save that line , delete the line in the array, then put the line back, modifying the particular field I need changed.

I am wondering if a memory table - which i know nothing about on pcsoft products - is a better solution. The array I build - is an array of years of a persons life - and contains various values as in, expected salary, various costs, expected inflation, expected tax bracket, etc. etc. . All of the fields or columns of this array are known at start - so I used a structured array to start this - but on other platforms ( i have written and rewritten this app since 1986) , i used what was called a memory table , basically a file with a couple keys (years, age) and a 50 or 60 fields - except its not stored on disk, its created, added to , modified and reported and displayed from memory.

Thanks.

Don



Edited 1 time(s). Last edit at 09/27/2018 04:03PM by donschwirtlich.
pao
Re: Modify a value on a structured array
September 27, 2018 05:45PM
Hi don,

I dont know if what you are talking about is one array of structures, something like this:
My_structure is structure
vari is int
vars is string
vard is date
end
my_array is dynamic array of my_structure

To add values use:
var_int is int
var_int=arrayadd(my_array)

To change the array values use:
my_array[var_int]:vari=1
my_array[var_int]:vars="xxxxxx"
my_array[var_int]:vard=today()

you don't need any special function to change the array values.

Regards

Paulo Oliveira



Edited 1 time(s). Last edit at 09/27/2018 06:01PM by pao.
Re: Modify a value on a structured array
September 27, 2018 06:02PM
Excellent Paulo, thanks. My thought was that since there was a function arrayadd to add the line out there , there had to be something else to modify it. I was writing a quick test to see what happened when I do - what you just advised me to do. Thanks.

Best regards

Don Schwirtlich
pao
Re: Modify a value on a structured array
September 27, 2018 06:06PM
You only need functions to manage the occurences (arrayadd, arraydelete,.....).
To change the values of the existing occurences you don't need any function.

Regards

Paulo Oliveira



Edited 1 time(s). Last edit at 09/27/2018 06:07PM by pao.
Re: Modify a value on a structured array
September 27, 2018 07:35PM
Hi Don,

In addition to Paolo's reply you can also modify an array in a loop like this:
FOR EACH ensSTBuffer of ar_MyArray
   IF ensSTBuffer.Condition="test" THEN ensSTBuffer.Value=NewValue
END
This saves you the trouble of the use of indexes.

Kind regards,
Piet
Re: Modify a value on a structured array
September 27, 2018 08:44PM
Thanks Piet, thanks Paolo, you have both been very helpful.

Kindest regards

Don



Edited 1 time(s). Last edit at 09/27/2018 08:45PM by donschwirtlich.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: