Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Help with Syntax - Last name irst name not working with an if clause (Read 837 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help with Syntax - Last name irst name not working with an if clause

I came across on this forum a code which displays name as Last Name first name. This worked:
$right(%Composer%, $sub($len(%Composer%), $strrchr(%Composer%, " "))),
$left(%Composer%, $sub($strrchr(%Composer%, " "),1))


Using this, I am tying to display last name- first name of composer if the genre is Classical and first name-last name of Album artist for non-classical in a column on Facets UI. When I tried the above syntax in an if-then-else sattement, the syntax did not work for me.

(Just for  testing purposes I used  Album Name to be displayed if the genre is NOt Classical, just to spot any errors easily. I will later change this to %Album artist%)

When I used the the above code for if true part of the condition I received an "Invaid Syntax" error:
$if($stricmp(%Genre%,Classical),$right(%Composer%, $sub($len(%Composer%), $strrchr(%Composer%, " "))),
$left(%Composer%, $sub($strrchr(%Composer%, " "),1))

,%Album%)

Putting the above condition in parantheses also did not work.This gave me a blank if genre is Classical and the Album Name if non-classical.
$if($stricmp(%Genre%,Classical),($right(%Composer%, $sub($len(%Composer%), $strrchr(%Composer%, " "))),
$left(%Composer%, $sub($strrchr(%Composer%, " "),1))
)
,%Album%)

How can I fix this?

Re: Help with Syntax - Last name irst name not working with an if clause

Reply #1
You need to escape the comma between first name and last name with single quotation marks, so it is not taken as a delimiter to the parameters of $if(). That is how it works on Default UI. I am not familiar with Facets, and the double quote syntax. The comma needs to be quoted anyway.

Code: [Select]
$if($stricmp(%Genre%,Classical),$right(%Composer%,$sub($len(%Composer%),$strrchr(%Composer%,' ')))', '$left(%Composer%,$sub($strrchr(%Composer%,' '),1)),%Album%)

Re: Help with Syntax - Last name irst name not working with an if clause

Reply #2
Thank you very much. Worked like a charm. I kept wondering how the program could know which commas are a part of the if statement and which are not, so tried putting the code in paratheses, since then playing with paratheses, $puts/$gets etc... never thought of this single quotes. I could not have thought of this, for sure. Thanks.

Arun