Flags

From MediaMonkey Wiki
Jump to navigation Jump to search

What's a flag in programming?

Flags in programming are like tags that can be added to a certain object: they're either present or not.


These flags are always numbers which are binary, literal values of which usually represented in hexadecimal (e.g. const FLAG = &H0001). E.g. for flags with binary values 0001 (&H0001), 0010 (&H0002), 0100 (&H0004) and 1000 (&H0008), we know that the flag value 1011 contains the 1st, 2nd and 4th flag.

Use flags in Visual Basic or VBScript

To add a flag, use OR (Or or +)

MyFlags = MyFlags Or FLAG

To remove a flag, use AND NOT (And Not)

MyFlags = MyFlags And (Not FLAG)

To check for the presence of a flag, use AND (And)

If MyFlags And FLAG
  ' FLAG is present
End If