Survey Tabulation > Advanced expressions > UNICOM Intelligence function library > Miscellaneous functions > BitOr
 
BitOr
Performs a bitwise OR on two or more numeric values and returns the result.
Syntax
BitOr(Val1 [, Vals, ...])
Parameters
Val1
Type: Long
First data value.
Vals
Type: None
Variable number of other values.
(return)
Type: Long
All values OR-ed together.
Remarks
Vals is a list if variants, which are converted to Long before they are used. If one or more of them cannot be converted to a Long value, an error occurs.
The return value is a number with only the bits set that are set in Val1 or in at least one of the other value arguments. If the current data value is NULL, Val1 is 0 and the return value is the combination of the other value arguments. If no other arguments are supplied, the return value is Val1.
This function is similar to using Or as a bitwise operator in Visual Basic.
Example
BitOr is used to combine bit patterns and can be used to test more than one bit at the same time. Like the other bit functions, BitOr, is useful when working with properties that store a numeric value in which the bits are used to record true or false values that represent whether various flags have been set. Typically a type definition is used to define the various flags.
This mrScriptBasic example refers to the MDM ObjectTypeValue property, which is used to record an object's types. The values are defined in the ObjectTypesConstants type definition. The example uses BitOr in combination with BitAnd to test for two bit patterns that correspond to the mtArray and mtGrid constants in the ObjectTypesConstants type definition:
Dim MyObject

For Each MyObject In MDM.Fields
If BitAnd(MyObject.ObjectTypeValue, _
BitOr(ObjectTypesConstants.mtArray, ObjectTypesConstants.mtGrid)) Then
' This is an an Array or Grid object ...
End If
Next
This is equivalent to:
For Each MyObject In MDM.Fields
If BitAnd(MyObject.ObjectTypeValue, ObjectTypesConstants.mtArray) OR _
BitAnd(MyObject.ObjectTypeValue, ObjectTypesConstants.mtGrid) Then
' This is an an Array or Grid object ...
End If
Next
BitOr is also useful for making sure that certain bits are set, without affecting the other bits. For example:
Dim ElemFlags

ElemFlags = BitOr(MDM.Fields["remember"].Categories["Not_answered"].Flag, _
    CategoryFlagConstants.flExclusive)
See also
Miscellaneous functions