Something that might help point you in a good direction:
search for 'filemaker JSON', for example, you'll see this:
or any of the plug-ins that work with "JSON".
you don't necessarily need to use JSON, but it has the name-value pairs that may be what you need to read & write.
It depends on what you are going to use it for. Typical an array like that is used to transfer data, for example as a script parameter between files. But if you really need to manipulate the data as an array, for example creating a report, then the 'array' maybe should be in a series of variables or in a FMP 'temporary' or 'reporting' table. If you are going to export this data then maybe an export table would be easier to handle.
Note: array's built in variables cannot use the Aggregate functions. For example Sum ( $$total ) won't work because the Function requires a real field.
There are quite a few CF (Custom Functions) for creating name-value pairs, see list from Beverly. If that's the use case then you can probably get what you need from one of those.
I'd like to know the purpose if its not one of the 'typical' uses.
Another approach would be to use a delimited variable mimicking an array, like this:
You can then extract values based on position. One way is to look for the pattern of the row, such as:
Set Variable [ $array ; "¶" & $array ]
Set Variable [ $desiredPosition ; Position ( $array ; $desiredName ; 1 ; 1 ) ] // Example: To locate "yellow", Position ( $array ; "yellow" ; 1 ; 1 )
Set Variable [ $leftPortion ; Left ( $array ; $desiredPosition ) ]
Set Variable [ $rowNumber ; PatternCount ( $leftPortion ; "¶" ) ]
Set Variable [ $desiredRow ; GetValue ( $array ; $rowNumber ) ]
Set Variable [ $desiredVal ; GetValue ( Substitute ( $desiredRow ; "|" ; "¶" ) ; 2 ) ]
It's simpler if you index the array and know what row you want. Then, you can just skip to the boldface steps and substitute the desired row number for $rowNumber.
There are some custom functions out there to help you build the array. If interested, I can post them.
OK, that's been done a few times and CF's are available to handle assigning and retrieving.
Set Array Cell
Get Array Cell
I'm pretty sure the MBS (Monkey Bread Software) plugin also has functions to handle creating variables and assigning values and retrieving. Visit Brian Dunnings site.
Thanks to all of you and these different approaches. I will work on it. But still, I find it strange not to have arrays genuinely implemented in FM.
HAve a great day!
My purpose is to create a temporary array of sizes and nb of items per size in order to then send into a table once it is validated.
thenprocess would be :
1/ entering the values (nb items) for the concerned sizes (some could remain empty)
2/ saving the array into a field in order to retrieve the data
3/ validation action (toggle button for example) to send the only sizes having a number of items > 0 to a sizes table
why do I want to it this way :
JJust because I
1/ don't want to create unnecessary records for empty sizes
2/ because the setting of sizes and numbers may change until final confirmation (but this isn't really a point)
more generally, I was wondering how to manipulate complex arrays.
as experts , if your advice is most welcome.
there is no native array-function built-in, besides of the simple array (aka repeating values for fields, scriptvariables). There are requests for arrays - but not very often, since there are quite some workarounds. We are using lists very often (2-dimensional, mostly for parameters), what serves very well - but 'array' goes beyond...
Maybe there are plugins available - and there is a feature request page: Company | FileMaker
Thanks for your comment
as a matter of fact I'm trying the relating values of a field that might be sufficient enough for my purpose.
There is a fairly detailed section on Arrays in Ray Cologon's FileMaker Pro 10 Bible—still a helpful reference work.
Yep! Until we get arrays, there are "lists" and quasi-lists and "virtual lists". Yes, repeating fields can also work. Yes you can have repeating variables. Whatever floats...
I'm not sure that this is useful for your purpose, but no one yet wrote
you can use Code() function to implement name-value pairs if name is shorter than 80 chars
Set Variable[ $array [Code($name)] ; $value ]
I think the above custom functions are for a two-dimensional array.
The following are to "Set [and get] a cell value in an arbitrary-dimensional array":
You can turn any list or variable with repetitions (one-dimensional variable array) into an array of any number of dimensions mathematically. Thus a list of 1000 can be indexed three-dimensionally (10 per dimension) like this:
Where x = 0...9; y = 0...9; z = 0...9.
GetValue( (x + y*10 + z*100) + 1 )
or $variable[ (x + y*10 + z*100) + 1 ]
The "+1" adjusts the addressing from 0...999 to FileMaker's 1...1000.
You can make the limits more variable like this:
Where x = 0...xlim; y = 0...ylim; z = 0...zlim.
Where yplace = xlim+1; zplace = (ylim+1)*yplace.
GetValue( (x + y*yplace + z*zplace) + 1 )
or $variable[ (x + y*yplace + z*zplace) + 1 ]
And, as seen from the custom Array functions, even the number of dimensions can be variable.
When I used to do this in C programming, I learned that the multidimensional arrays I was making could also be indexed as one-dimensional arrays; so apparently at least some multidimensional arrays are just one-dimensional arrays behind the scenes anyway.
...though the example you gave looks less like what I'd call a multidimensional array (from my complex examples above) and more like simple value-pairing. If that's the case, then I would just set an array like this:
$myArray = List("green¶2¶yellow¶6¶red¶2");
and retrieve it like this:
$color = GetValue( $myarray; $valueNumber);
$number = GetValue( $myarray; $valueNumber+1);
Where $valueNumber = ($row*2)+1
and $row starts at 0 and advance as $row = $row+1.
thank you very much Eric and all of you.
i may now close this question as I really have a lot of great information and how to's to deal with depending on my needs.