Author Topic: Using functions to check for a contained value rather than a complete value  (Read 11428 times)

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
There's no function that will let you directly check whether a tag contains a certain value when that value is not the complete tag.  However, I've discovered a kludge for this that some might find useful:

[Adjusted courtesy of redwing]

$If($Replace(<Tag>,"value",)=<Tag>,"Not Contained","Contained")
Last Edit: October 11, 2013, 09:17:17 PM by scampbll
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

redwing

  • Guest
There's no function that will let you directly check whether a tag contains a certain value when that value is not the complete tag.  However, I've discovered a kludge for this that some might find useful:

$IsNull($Split(<Tag>,"contained value",2),"result if value is not present","result if value is present")

That would work only for some special cases. With a value "Beethoven" for a tag "Ludwig van Beethoven" it returns null even though the value is present.

For stating "contain" and "does not contain" with virtual tags:
http://getmusicbee.com/forum/index.php?topic=9317.msg56608#msg56608

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
True, it requires that there be something after the search value.

Can you clarify how you're using Replace for this purpose?  I'm thinking it wouldn't work for values NOT at the end of the tag.
Last Edit: October 11, 2013, 05:05:46 PM by scampbll
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

redwing

  • Guest
Can you clarify how you're using Replace for this purpose?  I'm thinking it wouldn't work for values NOT at the end of the tag.

$If($Replace(<Composer>,"value",)=<Composer>,"Not Contained","Contained")

Probably this would work for any values regardless of its place. Think $Replace function as an eraser when it's used with blank "replace-text."

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
Maybe I'm misunderstanding how replace works.  Does it replace the whole tag, not just the search text?

... Oh, I get it.  Thanks!  I'll adjust my formulas, then.  :)
Last Edit: October 11, 2013, 09:06:17 PM by scampbll
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
i will add a function to support this as it seems it would often be useful, something like:
IndexOf(<field>, "text")
which would return -1 for no match, otherwise the zero-based index of the text
$If($IndexOf(<genre>,"Rock")<0,no-match-value,match-value)

i might also look at regular expressions but not promising that

redwing

  • Guest
i might also look at regular expressions but not promising that

That'd be wonderful and make any things possible with virtual tags! Please do!

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
i will add a function to support this as it seems it would often be useful, something like:
IndexOf(<field>, "text")
which would return -1 for no match, otherwise the zero-based index of the text
$If($IndexOf(<genre>,"Rock")<0,no-match-value,match-value)

Awesome!
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
$Contains is working great, thanks!

I've added both of these to the wiki, along with $Date.  Are there any other functions like Date that aren't shown in MB?
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

redwing

  • Guest
Thanks a lot!

Would be great if $Replace function supports regex pattern, too.

redwing

  • Guest
I've added both of these to the wiki, along with $Date.  Are there any other functions like Date that aren't shown in MB?

There are $And and $Or functions for $If conditions:
 
$If($And(<field1>=value1,<field2>=value2),true-value,false-value)

$If($Or(<field1>=value1,<field2>=value2),true-value,false-value)

Note that they might not work properly for more than two conditions.


Also have a look at this thread for any info possibly omitted from the wiki page:

http://getmusicbee.com/forum/index.php?topic=1626.msg26926#msg26926
Last Edit: October 13, 2013, 08:26:57 AM by redwing

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
Thanks.  I added $And and $Or.  Do those only work with $If, or would they function with $IsNull as well (since it's basically a special form of $If)?

Added: someone just asked on the wiki if it's possible to get more than 2 criteria by nesting $And statements, i.e.
Code
$And(Criteria 1,$And(Criteria 2,Criteria 3))
Last Edit: October 13, 2013, 03:53:04 PM by scampbll
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)

redwing

  • Guest
Just tested it and it's not working. I remember there was a wishlist item (or a bug report?) that requested supporting more than two conditions for $And and $Or function.

Not sure what you meant by $IsNull and those functions. I don't know any other cases $And and $Or would work except for $If conditions.

psychoadept

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 10691
Not sure what you meant by $IsNull and those functions. I don't know any other cases $And and $Or would work except for $If conditions.

Well, you could just as legitimately want to run a formula $IsNull($And(<Tag 1>,<Tag 2>),true,false).
MusicBee Wiki
Use & improve MusicBee's documentation!

Latest beta patch (3.5)
(Unzip and overwrite existing program files)