Gary, if I understand your request, maybe you could use
x = IFF(x = u1, u2, u1)
to toggle between x = u1 and x = u2
Announcement
Collapse
No announcement yet.
Flipping the checked state of a menu item
Collapse
X
-
Originally posted by Gary Beene View PostIn a more general case, flipping between two values could require multiple bit flips, unique to the numbers involved.
Code:Bits2Flip = %Property1 OR %Property2 BitField = (BitField XOR Bits2Flip)
Leave a comment:
-
Hi Scott,
Bit flipping as you describe works well for a case like %MF_CHECKED (&H8) and %MF_UNCHECKED (&H0), where a flipping a single bit would convert between the desired values. I like that.
In a more general case, flipping between two values could require multiple bit flips, unique to the numbers involved.
My post was to inquire if there are some general algorithms, like these:
Toggle between 1 and 0
Code:A = NOT A (well, in VB anyway)
Code:x = x XOR 1
Code:x = 3-x
Code:IF iState = 1stvalue Then iState = 2ndValue Else iState = 1stValue End if
Last edited by Gary Beene; 6 Mar 2009, 10:03 AM.
Leave a comment:
-
Bit Values can be toggled by using XOR.
Where:Code:Local Flags As Dword Flags = 1 ' Bit 0 ON Flags = (Flags Xor 2) ' Toggle Bit 1 (Value of 2) (was off will be on) ? Format$(Flags) ' verify that both Bits 0 and 1 are on (Values 1+2 should = 3) Flags = (Flags Xor 2) ' Toggle Bit 1 (Value of 2) (was on will be off) ? Format$(Flags) ' verify that Bit 1 remains on, but Bit 2 is back off (should = 1)
Turn them off with AND NOT
Leave a comment:
-
Thanks, Micheal.
Your approach would work regardless of the values of the two options. Neither has to be zero.
Leave a comment:
-
Generally bit masks are managed with the boolean operators AND, OR, NOT, etc.
Untested but should work..
Code:Menu get State .... to iState Menu set State ..... IIF&(iState AND %MF_CHECKED), %MF_UNCHECKED, %MF_CHECKED)
Leave a comment:
-
Flipping the checked state of a menu item
I wrote these two lines of code, which flip the check state of a menu item between %MF_CHECKED (&H8) and %MF_UNCHECKED (&H0).
It works, but only because one of the two values was a zero, making it possible to use the IsFalse the way I did.
Code:Menu Get State hMenuOptions, ByCmd %ID_Backup To iReturn Menu Set State hMenuOptions, ByCmd %ID_Backup, Abs(IsFalse iReturn)*8
If both values were non-zero, this longer code would also work:
Code:IF iState = 1stvalue Then iState = 2ndValue Else iState = 1stValue End if
Just thought I'd see if there was a common, simpler approach that I've not run across.Tags: None
Leave a comment: