SYMPTOMS
The
IsFirstInTransaction property of a Microsoft Message Queuing MSMQMessage object returns an integer result rather than a Boolean.
IsFirstInTransaction returns a 1 if the message is the first in the transaction and a 0 if it is not. This can cause logic errors in a Visual Basic (VB) program if the property is used in the expression portion of an
If,
While, or similar conditional statement.
When a numeric value is used in a condition statement in VB, 0 is evaluated as false and all non-zero values are evaluated as true. The
Not operator in VB inverts the bits of a value when used on a numeric value. The expression "Not 1" produces the result "-2" which is considered a "true" value in a VB condition statement.
Since VB evaluates both "1" and "Not 1" as true statements, if a message is the first in a transaction both "message.IsFirstInTransaction" and "Not message.IsFirstInTransaction" will evaluate true. In the following example code, if the message is the first in a transaction both message boxes appear:
If message.IsFirstInTransaction Then
MsgBox "The message was the first message sent in the transaction."
End If
If Not message.IsFirstInTransaction Then
MsgBox "The message was not the first message sent in the transaction."
End If
REFERENCES
MSDN Online Help for the MSMQMessage Object
Visual Basic Programmer's Guide
246218 MSMQMessage Object IsAuthenticated Property Returns an Integer
246222 MSMQQueueInfo Object IsTransactional Property Returns An Integer
246225 MSMQQueueInfo Object IsWorldReadable Property Returns and Integer
245753 MSMQQueue Object IsOpen Property Returns an Integer
246460 MSMQMessage Object IsLastInTransaction Property Returns An Integer