Microsoft KB Archive/245753

= The MSMQQueue object IsOpen property returns an integer =

Article ID: 245753

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Message Queue Server 1.0
 * Microsoft Message Queuing 2.0

-



This article was previously published under Q245753



SYMPTOMS
The IsOpen property of a Microsoft Message Queuing MSMQQueue object returns an Integer result rather than a Boolean.

Note Microsoft Message Queuing is also known as MSMQ.

The IsOpen property returns a 1 if the queue is open 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 queue is open both "queue.IsOpen" and "Not queue.IsOpen" will evaluate true. In the following example code, if the queue is open both message boxes appear: If queue.IsOpen Then MsgBox "The queue is open" End If

If Not queue.IsOpen Then MsgBox "The queue is closed" End If



RESOLUTION
There are two possible workarounds for the problem:   Explicitly test the value of the IsOpen property against 0 and 1. A value of 1 indicates that the queue is open, a value of 0 indicates that the queue is not open. An example of this test is shown in the following code:

If MSMQQueueObject.IsOpen = 1 Then MsgBox "The queue is open." End If

If MSMQQueueObject.IsOpen = 0 Then MsgBox "The queue is closed" End If                        Avoid "negative" tests that use the Not operator with the IsOpen property.



STATUS
It is safe to test explicitly for the 1 and 0 values. These values will not be changed in any future version of Microsoft Message Queuing and will remain consistent. Future versions of the Microsoft Message Queuing ActiveX components may add a property that may be evaluated as a true Boolean type for testing this characteristic.



MORE INFORMATION
The MSDN Online help describes the return values for the IsOpen property as follows: MSMQQueue.IsOpen

Return Values 1   The queue is open. 0   The queue is not open.

