Jump to content

List variable


H1sc

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

Recommended Posts

I'm sure I'm missing something obvious, but I cannot find the answer to this. I'm not a programmer, but I had a very little experience with python, and I used to use list variables. How do I use them on FileMaker Pro? I would really love to set a list and be able to retrieve the last value, the first, the third, etc. I remember in python it was as easy as ListName[numberofitem], and I could even use ListName[-numberoftheitembackwards]

 

Am I missing something obvious? Isn't it possible to define a list variable in filemaker pro?

Link to comment
Share on other sites

Check out the native FM functions GetValue(), FilterValues(), LeftValues(), RightValues(), MiddleValues(), ValueCount(), ValueListIDs(), ValueListItems() and ValueListNames(). There is alot of power when these are combined with the other native functions, script steps and custom functions

Link to comment
Share on other sites

There are two main ways to approach list data structures in FileMaker: return-delimited lists, and "repeating" variables.

 

Return-delimited lists are text strings with elements separated by returns. You can build them by concatenating values with returns or by using the list function:

$valueOne & ¶ & $valueTwo & ¶ & $valueThree
List ( $valueOne ; $valueTwo ; $valueThree )

(The difference between the two is that concatenating returns will preserve empty values. If $valueTwo is empty, the first list above is 3 values long, and the second list is only 2 values long. The GetValue function is good for retrieving values one at a time. The LeftValues, MiddleValues, and RightValues functions are good for retrieving ranges of values; but be careful to watch for trailing returns in the result you get. IsEmpty ( FilterValues ( $testValue ; $valueList ) ) is the de facto standard construction for testing if a value exists in the list. (For the best calculation performance, always put the list you expect to be shorter as the first parameter to the FilterValues function.) You can store values with returns in return-delimited lists by using the Quote function on each value when you're building the list, and the Evaluate function when pulling values back out again:

List ( Quote ( $valueOne ) ; Quote ( $valueTwo ) )
Evaluate ( GetValue ( $valueList ; 2 ) )

Repeating variables behave similarly to (but not exactly like) repeating fields, only with variables. The Set Variable script step allows you to specify a repetition, and you can address different repetitions in a calculation by including the desired index in square brackets after the variable name. The 1st repetition of any variable is the same as the variable with no repetitions at all:

$variable[1] = $variable    // same variable

Each approach has it's pros and cons. Return-delimited lists store the list in a single variable that you can manipulate as a whole, and you can use the ValueCount function to know how long a list is. Repeating variables are not a single list variable so much as several separate variables using the same name with an index to tell them apart — you can't manipulate the list as a whole without building yourself some helper functionality, only each value in it — and there's no built-in function that will tell you how many repeating variables there are for the same name. You just have to keep track of how long the list is for yourself like you would with an array in C (though the consequences of getting it wrong are much less severe than in C!). But it's much faster to access individual values in repeating variables than in return-delimited lists, especially with longer lists.

Link to comment
Share on other sites

Repeating variables behave similarly to repeating fields, only with variables.

 

I wouldn't say that. There are lots of things that repeating fields do that repeating variables don't.

 

For example, List ( RepeatingField ) returns a list of values in all non-empty repetitions of the field. OTOH, List ( $repeatingVariable ) returns ... well, nothing particularly useful.

 

In fact, there is nothing "repeating" about repeating variables: each repetition is a completely independent variable with nothing in common with the other repetitions except the first part of the variable name.

  • Like 1
Link to comment
Share on other sites

One other quirk I forgot to mention about repeating variables is that they accept negative indexes, but they don't behave like you're used to in Python. There is no "list" to address as a whole with a series of repeating variables, so there's no end of the list to count backwards from. But negative indexes still work. The negative integers just all map to separate repetitions.

  • Like 1
Link to comment
Share on other sites

I did not know that. I can't think of any use of that off the top of my head....have you found a use for it?

 

I have used that before. I can't remember what it was, but it did turn out to be handy.

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I am reading your discusion about "list variable" but I have a problem to get the list of values from a repeating field from a local variable ($Prot_uncovered). I am using List ( RepeatingField ) function to returns the list of values but I only get a "?" symbol. I don´t understand where is the problem because in the inpector I have the values but I don´t get the list of all of them. Could anyone help me?

 

I attach an example file. Only run the script to see my problem.

https://www.dropbox.com/s/cw6pn0xtwbu5h56/example.fmp12

 

Thank you very much,

Wardiam

Link to comment
Share on other sites

I am reading your discusion about "list variable" [ … ]

 

But you seem to have missed post #4.

 

[ … ] OTOH, List ( $repeatingVariable ) returns ... well, nothing particularly useful.

In fact, there is nothing "repeating" about repeating variables: each repetition is a completely independent variable with nothing in common with the other repetitions except the first part of the variable name.

 

Instead of using List() after the loop, use it within:

 

Loop

Set Variable [ $myList ; List ( $myList ; someValue ) ]

End Loop

Link to comment
Share on other sites

Instead of …

 

Loop

  Set Variable [ $i; Value:$i +1 ]
  Exit Loop If [ $i > $ocurrences ]
  Set Variable [ $Prot_uncovered[$i]; Value:ParseData ( $Prot_seq_CSS; "<SPAN STYLE= " & """ >"; "</SPAN>" ; $i ) ]

End Loop
Set Field
[ Proteins::UnCover_SEQ; List ( $Prot_uncovered )

 

… try

 

Loop

  Set Variable $i; Value:$i +1 ]
  Exit Loop If $i > $ocurrences ]
  Set Variable $myList ; Value: List ( $myList ; ParseData ( $Prot_seq_CSS; "<SPAN STYLE= " & """ >"; "</SPAN>" ; $i ) ) ]

End Loop
Set Field 
Proteins::UnCover_SEQ ; $myList

 

And on a related topic: In the other thread you've asking how to count bold characters. Since I take that you're setting the bold formatting yourself, within this very script, why not keep count of the number of characters that you format, while you're doing it?

 

And last but not least: no need for Dropbox, you can attach a file directly to a post, you just need to compress it (while it's closed).

Link to comment
Share on other sites

Thanks again eos, I have reviewed my script and I have detected my error. Adding the $mylist variable, I have included repetitions as $i. Then I have removed it and that's all, it works.

By other way, It's true, I did this script to count bold characters in my text (sequence). I am very interesting in your suggestion to keep count of the number of characters that I format but I don't know how to do it. Could you help me?

 

Wardiam

Link to comment
Share on other sites

Thanks again eos, I have reviewed my script and I have detected my error. Adding the $mylist variable, I have included repetitions as $i. Then I have removed it and that's all, it works.

 

Forget repetitions and think of what you're building as a list (and make sure to remove the repetition parameter from the Set Variable step).

 

By other way, It's true, I did this script to count bold characters in my text (sequence). I am very interesting in your suggestion to keep count of the number of characters that I format but I don't know how to do it. Could you help me?

 

I'm not familiar enough with the topic matter to know if what you're trying is substitute is guaranteed to be actually substituted; if that is the case, you could simply use the length of the substitution string:

Set Variable $subCount; Value:$subCount + Length ( $Pep_seq ) 

 

Otherwise (best thing I can come up with) perform a dummy substitution and subtract ‘after’ from ‘before’:

Set Variable [ $subCount; Value:$subCount + Length ( $Prot_seq ) - Length ( Substitute ( $Prot_seq ; $Pep_seq ; "" ) )

 

As shown, keep a running counter within the loop, and at the end of the script, write its value into a field (or use it however you see fit).

 

and that's all, it works.

 

One More Thing: Your script is probably not working properly, for two reasons (OK, two more things …)

 

1. Note the variable names in bold. This is supposed to be the same variable, but it ain't so …

 

Set Variable [ $$Prot_seq_CSS; Value:GetAsCSS ( $Prot_seq ) ]

Set Variable [ $ocurrences; Value:PatternCount ( $Prot_seq_CSS ; "<SPAN STYLE= " & """ >" )

 

Better use $local, unless you really need $$global.

 

2. The Pattern you're trying to Count doesn't appear in this form. But then again, unless I'm mistaken, you're only parsing out the stuff you substituted in earlier, so in the first loop you could not only keep a running count of how much, but also a list of what you substituted.

Edited by eos
Link to comment
Share on other sites

Hi eos,

 

I have tried your both suggestions:

  • Set Variable $subCount; Value:$subCount + Length ( $Pep_seq ) 
  • Set Variable $subCount; Value:$subCount + Length ( $Prot_seq ) - Length ( Substitute ( $Prot_seq ; $Pep_seq ; "" ) ) 

and they works to count the number of characters that are replaced (great!!!!) but the problem is more difficult; the sequences that are substituted can be overlapped (have matching characters) therefore at the end the global sequence without bold characters is different. With your suggestions, I can get 184 replaced characters and really are 170 in the global text. This is the reason because I thought to obtain the "normal text" (without bold style) and calculate its length or conversely, get the bold text and deduct its length to the total length.

 

What do you think now?

 

Wardiam

Link to comment
Share on other sites

What do you think now?

 

Wardiam

 

“Holy cow” is what I think now … then you can remove this nice line out of the first loop and use your other method. Got it working yet? If not, try this:

 

Set Variable [ $occurrences; Value:PatternCount ( $Prot_seq_CSS ; "color" ) ]

Loop

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

Exit Loop If $i > $occurrences ]

Set Variable [ $boldcount; Value:$boldcount +

Let ( [

c = Position ( $Prot_seq_CSS ; "color" ; 1 ; $i ) ;

ot = Position ( $Prot_seq_CSS ; ">" ; c ; 1 ) ;

ct = Position ( $Prot_seq_CSS ; "<" ; c ; 1 )

];

ct - ot - 1

)]

End Loop 

Link to comment
Share on other sites

Great eos!!!!

 

this is exactly what I wanted. At the end I was using the custom function from the other post but I want to learn how can I do it and your script is very instructive and I'm going to study it. Of course, it works.

 

You can keep thinking about the "holy cow"  :sweat:

 

Thank you very much,

Wardiam

Link to comment
Share on other sites

This topic is 3803 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.