Trouble using ParamList

Hi, this must be such a basic question, however, despite searching online, I can't work it out....
According to the AFL Reference guide, ParamList returns "...a STRING representing chosen item." It also describes the defaultVal which defines the ordinal position of the default value.

Based on this, I don't understand why my sample code always displays the final option from the parameter list. I've also uploaded a picture of my debug Output window.

printf("**** A - The assignment of each ParamList variable\n");
aaa = ParamList("Option Number", "option1|option2|option3", 0 );
bbb = ParamList("Option Number", "option1|option2|option3", 1 );
ccc = ParamList("Option Number", "option1|option2|option3", 2 );
ddd = ParamList("Option Number", "option1|option2|option3", 3 );


printf("\n");
printf("**** B - printf each ParamList variable\n");
printf(aaa+"\n");
printf(bbb+"\n");
printf(ccc+"\n");
printf(ddd+"\n");


printf("\n**** C - About to conditionally print the default param list values for aaa\n");
if (aaa=="option1") 
	printf("aaa is option1");
else 
	if (aaa=="option2") 
		printf("aaa is option2");
	else 
		if (aaa=="option3") 
			printf("aaa is option3");
		else 
			printf("no clue what aaa is...");

screenshot

Because all variables hold same name (-> "Option Number" ) in ParamList first argument.
AFL uses last one since execution of formula goes from top to bottom.

So use distinct names for each variable.

E.g.

printf("**** A - The assignment of each ParamList variable\n");
aaa = ParamList("Option Number 1", "option1|option2|option3", 0 );
bbb = ParamList("Option Number 2", "option1|option2|option3", 1 );
ccc = ParamList("Option Number 3", "option1|option2|option3", 2 );
ddd = ParamList("Option Number 4", "option1|option2|option3", 3 );


printf("\n");
printf("**** B - printf each ParamList variable\n");
printf("aaa: %s\n", aaa);
printf("bbb: %s\n", bbb);
printf("ccc: %s\n", ccc);
printf("ddd: %s\n", ddd);


printf("\n**** C - About to conditionally print the default param list values for aaa\n");
if (aaa=="option1") 
	printf("aaa is option1");
else 
	if (aaa=="option2") 
		printf("aaa is option2");
	else 
		if (aaa=="option3") 
			printf("aaa is option3");
		else 
			printf("no clue what aaa is...");

57

"ddd" by default returns empty string in "**** A ..." and "**** B" of Interpretation window output because you have entered '3' as default value to 3rd argument there but there are only 3 "option" substrings

option1|option2|option3

and indexing being zero based. So in your case it goes from 0 to 2. So "ddd" becomes empty by default since there is no 4th substring.

5 Likes

Thanks for your reply. That helps, I didn't realise the name needed to be unique. I just also found that the parameters are cached and need resetting using the RESET ALL button on the Analysis > Parameters window. Without doing this, any changes made in the code to the defaulVal have no effect. This didn't help when I was trying to work out what was going on.

Thanks again for your time. Much appreciated.

Regards, Tim.

Yes, they are cached but you do not have to click reset all (if you do not want to reset params of Parameter window but just want to update new formula state). To do this you can just open your applied formula in Formula editor and click "Apply" button of formula editor's tool bar. That will update all params also (without resetting all other existing ones being set to non default ones in Parameter window). This avoids annoying setting of multiple Params again if you have changed formula (and old non-existing Params having become obsolete but still having existed in Parameter window before clicking "Apply" and when you have clicked "Save" button only.)

DIfference between "Save" and "Apply" buttons of Formula editor:
"Save" saves formula.
"Apply" saves, verifies formula and updates applied formula state.

928

4 Likes

Thanks fxshrat. Much appreciated.