Jump to content
maniootek

How does decimal flag works as a parameter in function?

Recommended Posts

maniootek

For example, first parameter for function MsgBox() is "flag" which " indicates the type of message box and the possible button combinations." (according to help file)

If I want MsgBox with only "YES" or "NO" button and "QUESTION" icon then I have to pass to flag parameter value "4+32" (36).

Now, how MsgBox know that 36 represents option 4 and option 32? I belive it is mathematic function but don't know which.

I am asking it because I want make my own function with one parameter which could be many of possible combinations.

Share this post


Link to post
Share on other sites
czardas

It is a binary flag. Bits can be set using BitOr(). You should use BitAnd() to check which bits have been set. For example the number 5 is represented by '0101' in binary. Bits are set in the first and third positions (right to left). The example is demonstrated below.

Local $iFlag = BitOR(1, 4)

MsgBox(0, "Flag", $iFlag)
MsgBox(0, "1", BitAND($iFlag, 1) = 1) ; True - 1st bit is set
MsgBox(0, "2", BitAND($iFlag, 2) = 2) ; False - 2nd bit has not been set
MsgBox(0, "4", BitAND($iFlag, 4) = 4) ; True - 3rd bit is set


See what happens when you change the first line of the code to this:

Local $iFlag = BitOR(1, 4, 5)

Read about Bitwise functions in the help file to find out why it behaves the way it does.
 

Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×