gmaxey
09-21-2011, 05:25 AM
In a separate thread I was attempting to show how to validate a command button. The requirement was a collection of optionbutton groups "all" had to evaluate as True (at least one selected in each frame) before the CB was enabled.
I cobbled together something that worked but after thinking about it, I came up with this:
Sub IfOneFalseAllFalse()
'A quick macro scratch pad created by Greg Maxey
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean, b4 As Boolean
b1 = True
b2 = True
b3 = False
b4 = True
Dim bAll As Boolean
bAll = b1 * b2 * b3 * b4
MsgBox bAll
End Sub
Sub IfOneTrueAllTrue()
'A quick macro scratch pad created by Greg Maxey
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean, b4 As Boolean
b1 = False
b2 = False
b3 = True
b4 = False
Dim bAll As Boolean
bAll = b1 + b2 + b3 + b4
MsgBox bAll
End Sub
Both procedures return the correct result or "If One Fasle All False" and "If One True All True."
I just don't understand why it works! Math is not my strong suit but I thought if you multiplied two "-" numbers the result was positive. If that is still true then is seems that if in the first macro two values where false then the overall result would be true.
Can someone explain how this works and comment on the soundness of this method or if there is a better way?
Thanks.
I cobbled together something that worked but after thinking about it, I came up with this:
Sub IfOneFalseAllFalse()
'A quick macro scratch pad created by Greg Maxey
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean, b4 As Boolean
b1 = True
b2 = True
b3 = False
b4 = True
Dim bAll As Boolean
bAll = b1 * b2 * b3 * b4
MsgBox bAll
End Sub
Sub IfOneTrueAllTrue()
'A quick macro scratch pad created by Greg Maxey
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean, b4 As Boolean
b1 = False
b2 = False
b3 = True
b4 = False
Dim bAll As Boolean
bAll = b1 + b2 + b3 + b4
MsgBox bAll
End Sub
Both procedures return the correct result or "If One Fasle All False" and "If One True All True."
I just don't understand why it works! Math is not my strong suit but I thought if you multiplied two "-" numbers the result was positive. If that is still true then is seems that if in the first macro two values where false then the overall result would be true.
Can someone explain how this works and comment on the soundness of this method or if there is a better way?
Thanks.