Jump to content

Does filemaker have Arrays? There has got to be a better way to do what I need to do.


This topic is 6159 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Ok so heres what I need to do, I have a many 2 many relations ship built between two tables Lists and Elements. I want to build a merge to new list feature. Whats the easiest way to do this.

The new list should reference the existing Elements so changes made in the new merged list also appear in the original lists. Heres my current algorithm.

1. Create new list Get ID

2 Go to list Layout Select List to merge.

3. Begin Looping though selected.

4. Go to List Elements Layout.

5. Search for first List and get Element Id For each in a Loop

6. Go to many2many table and build link from new list to each element.

7. Loop back to 5. for each element. search for remaining elements

8. Loop back to 2 for each loop search for remaining lists

Does FM have arrays where I could just load say selected list into an array. Then load each of the list's element id into an array... That way I could build all the links at once by filtering though the array?

How does one go about this without the mess of switching Layer and Researching all the time?

Link to comment
Share on other sites

I'm not sure how your data is actually structured based on your description, and it would seem that there's probably a better way to do whatever it is you're describing without having to merge lists.

To answer your question about arrays, one way to approximate an array in filemaker is to just use a return delimited text field where each line is an element. There are functions to allow access to each line (value) and manipulate the array. (GetValue, LeftValues, RightValues, ValueCount, FilterValues as well as all the standard text manipulation functions like Substitute etc.)

You can also use repeating fields as arrays since you can reference specific repititions in a calculation formula.

Link to comment
Share on other sites

You can also build arrays up using repeating variables -- much easier.

If you had say 3 repeating variables, $name, $id and $number.

Loop

Set Variable[$i ; Value: $i+1]

Set Variable[$name[$i] ; Value: FirstName]

Set Variable[$pk[$i] ; Value: PK]

Set Variable[$number[$i] ; Value: PhoneNumber]

Go To Record[Next ; Exit After Last]

End Loop

Set Variable[ $length ; Value: $i ]

Set Variable[ $i ; Value: 0 ]

Go To Layout[ some layout ]

Loop

Set Variable[$i ; Value: $i+1]

New Record

Set Field[FirstName ; Value: $name[$i]]

Set Field[PK ; Value: $PK[$i]]

Set Field[ PhoneNumber ; $number[$i]]

Exit Loop If[$length = $i]

End Loop

Link to comment
Share on other sites

You can also build arrays up using repeating variables -- much easier.

If you had say 3 repeating variables, $name, $id and $number.

Ya, I really don't like creating variables for the sake of creating variables... much easier to manage with a single array variable... now that I have it figured out its way easy...

I have Push, Pop, Get, Place, Num, Loc all written already and when I get time I'll add functionality to Sort, multi_dim, and var allocation aka $fname=>fname... etc.

usage works somthing like this

Set Variable[$list_Array;simple_array($list_Array;$var2add)]

Link to comment
Share on other sites

They're not being created for the sake of being created... It takes longer to parse text and substitute characters than it does to retrieve a piece of data from the index of a basic variable.

Also note, these are local variables, they die after the script dies.

Besides, variables are variables, you could create a 1000 with little performance deficit...

Further you don't prepend $ to a key in any language that I know of unless the key itself is a variable in which case... and if you feel like parsing the data its fairly easy. While the following example isn't brilliant, its pretty powerful i suppose:


Let( [

assignmentList = "key=>value,key2=>value2,key3=>value3"; 

key = "key2" ;

newList = ¶ & Substitute( assignmentList ; "," ; "¶" ) & ¶;

keyStart = Position( newList ; ¶ & key & "=>" ; 1 ; 1 ) ;

valueStart = keyStart + Length(key)+3;

valueEnd = Position( newList ; "¶" ; valueStart ; 1 )];



If( PatternCount( newList ; ¶ & key & "=>" )  ; Middle( newList ; valueStart ; valueEnd - valueStart) ; "?" )



)

Anywho, just my opinion -- most times in scripts, especially with local variables, it is not important to be able to pull the array apart logically as long as the script can... and an index associated group is often more than enough.

Link to comment
Share on other sites

This topic is 6159 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.