Cyberdude
04-22-2007, 01:03 PM
I defined a single cell with the name ?Flags?, which can have numeric values from ?0? to ?7?.
The values of the ?Flags? cell have the following meaning:
???FlgA?..FlgB?FlgC????????Interpretation
???...0???0???.0??? (=0) ??FlgA & FlgB & FlgC = 0
???...0???0???.1??? (=1) ??FlgC = 1
???...0???1???.0??? (=2) ??FlgB = 1
???...0???1???.1??? (=3) ??FlgC & FlgB both = 1
???...1???0???.0??? (=4) ??FlgA = 1
???...1???0???.1??? (=5) ??FlgA & FlgC both = 1
???...1???1???.0??? (=6) ??FlgA & FlgB both = 1
???...1???1???.1??? (=7) ??FlgA & FlgB & FlgC = 1
My first problem is how to set the individual values of the bits in cell ?Flags? using VBA statements?
I do not want to fetch the current value of ?Flags? before changing the value of one of the bits, since that would reduce the efficiency of using a single cell to store a group of flag values. (Note that in practice there will actually be 16 bits.) I might add that the Msgbox statement uses this technique to handle the specification of the list of optional buttons.
How do I test the ?Flags? cell to determine the status of FlgA, FlgB, and FlgC?
For example, I want to write the equivalent of the following IF statement:
If Range(?FlgA?) = 1 And Range(?FlgB?) = 0 And Range(?FlgC?) = 1 Then . . .
Presumably, since the combination ?101? is the binary value of ?5?, I could write:
If Range(?Flags?) = 5 Then . . .
But if I want to write the statement:
If Range(?FlgA?) = 1 And Range(?FlgB?) = 0 Then . . .
I could write either of the following and be correct because I?m testing only the leftmost 2 digits to see if they are ?10?:
If Range(?Flags?) = 4 Then . . .
If Range(?Flags?) = 5 Then . . .
So which one should I write?? Is there a better way?
The values of the ?Flags? cell have the following meaning:
???FlgA?..FlgB?FlgC????????Interpretation
???...0???0???.0??? (=0) ??FlgA & FlgB & FlgC = 0
???...0???0???.1??? (=1) ??FlgC = 1
???...0???1???.0??? (=2) ??FlgB = 1
???...0???1???.1??? (=3) ??FlgC & FlgB both = 1
???...1???0???.0??? (=4) ??FlgA = 1
???...1???0???.1??? (=5) ??FlgA & FlgC both = 1
???...1???1???.0??? (=6) ??FlgA & FlgB both = 1
???...1???1???.1??? (=7) ??FlgA & FlgB & FlgC = 1
My first problem is how to set the individual values of the bits in cell ?Flags? using VBA statements?
I do not want to fetch the current value of ?Flags? before changing the value of one of the bits, since that would reduce the efficiency of using a single cell to store a group of flag values. (Note that in practice there will actually be 16 bits.) I might add that the Msgbox statement uses this technique to handle the specification of the list of optional buttons.
How do I test the ?Flags? cell to determine the status of FlgA, FlgB, and FlgC?
For example, I want to write the equivalent of the following IF statement:
If Range(?FlgA?) = 1 And Range(?FlgB?) = 0 And Range(?FlgC?) = 1 Then . . .
Presumably, since the combination ?101? is the binary value of ?5?, I could write:
If Range(?Flags?) = 5 Then . . .
But if I want to write the statement:
If Range(?FlgA?) = 1 And Range(?FlgB?) = 0 Then . . .
I could write either of the following and be correct because I?m testing only the leftmost 2 digits to see if they are ?10?:
If Range(?Flags?) = 4 Then . . .
If Range(?Flags?) = 5 Then . . .
So which one should I write?? Is there a better way?