INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Basic Expression problem -- why isn't IF working for me?  (Read 512 times)

bspachman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 896
Basic Expression problem -- why isn't IF working for me?
« on: December 31, 2020, 01:54:33 pm »

I've been using MC (& MJ) for so long, I'm a little embarrassed to ask the following question:

I'm trying to create a new library field that is calculated. Basically, if the track name starts with a "#" (hash, octothorp), do one thing, if not, do another.

However, I can't get the IF expression to evaluate properly.

Code: [Select]

If(Left([Name],1)=#,TRUE,FALSE)

Always evaluates to TRUE in the displayed column, regardless of whether or not the Name of the track starts with a "#".

I've also tried quoting the hash ("#"), escaping the hash (/#), and fully escaping the hash (/###/). All I see is TRUE in the library.

What basic thing am I doing wrong? :)

Thanks,
brad
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Basic Expression problem -- why isn't IF working for me?
« Reply #1 on: December 31, 2020, 02:38:45 pm »

Have you actually looked at the Wiki? Reading it can prevent the embarrassment you describe:
https://wiki.jriver.com/index.php/Conditional_Functions#If

Look at the first example there, and adapt it to your needs.

Your problem isn't the IF expression, it's the test you conduct within it. You cannot use = as a test operator in the expression language. That =# is just wrong. You must use the IsEqual expression.  So use Left within an IsEqual.
Logged

bspachman

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 896
Re: Basic Expression problem -- why isn't IF working for me?
« Reply #2 on: December 31, 2020, 02:53:19 pm »

Thanks! Worked a treat.

FWIW, I did examine the Wiki, but in my defense, none of the IF examples actually explain what a test expression is :) I probably should have just looked at my other (much older) renaming expressions to get a clue that ISEQUAL was the key.

Have a great New Year Everyone!
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Basic Expression problem -- why isn't IF working for me?
« Reply #3 on: December 31, 2020, 03:41:30 pm »

none of the IF examples actually explain what a test expression is :)

Expressions are expressions. In that example, true expression, false expression, and test expression are just expressions, which are given labels to indicate to you what they are.

Reading the opening paragraphs of the Expression Language wiki shows what expressions are and how they are constructed and evaluated. It gives examples if If() and IsEqual() expressions.  Using an infix operator, like a=5 is something the MC expression language never does, except in the Math() expression.  The wiki provides examples of correct syntax, but it is not customary to provide examples of possible bad syntax. 

The MC expression language is an example of a language developed to provide maximum ease for the progrmmers who were creating the language parser, not for the programmers/users actually writing in the language. So unfortunately the MC language doesn't use many common syntactic conventions prevalent in other languages.

I hope this helps.  Glad you got it figured out.
Logged
Pages: [1]   Go Up