The Reset method returns the cursor to the start of the results of a query, or to the start of a queue.
object.Reset
| Syntax Element | Description |
| object | Collection (MSMQQuery) object that represents a collection of queues, or queue (MSMQQueue) object that represents an open instance of a queue. |
For information on return codes, see MSMQ Error and Information Codes.
This example assumes that at least one queue whose label is "Test Queue" already exist. It runs a query for the test queues, then displays the format name of the first queue it found.
To try this example using Microsoft® Visual Basic® (version 5.0), make sure the Microsoft Message Queue Object Library is referenced, then paste the following code into the code window of a form, run the example, then click on the form.
Dim query As New MSMQQuery
Dim qinfos As MSMQQueueInfos
Dim qinfo As MSMQQueueInfo
Private Sub Form_Click()
Set qinfos = query.LookupQueue(Label:="Test Queue")
qinfos.Reset
Set qinfo = qinfos.Next
MsgBox "I found a Test Queue! its Format name is: " + FormatName
End Sub
This example assumes that a queue exists, opens the queue for receiving messages, looks at the label of each message in the queue, and then resets the cursor to the start of the queue.
To try this example using Microsoft® Visual Basic® (version 5.0), make sure the Microsoft Message Queue Object Library is referenced, then paste the following code into the code window of a form, run the example, then click on the form.
Dim qinfoMyQueue as MSMQQueueInfo
Dim qMyInputQueue as MSMQQueue
Dim msgMyMessage as MSMQMessage
'Open queue as an input queue (set Access to MQ_RECEIVE_ACCESS).
Set qMyInputQueue = qinfoMyQueue.Open (Access := MQ_RECEIVE_ACCESS, ShareMode := MQ_DENY_NONE)
Set msgMyMessage = qMyInputQueue.PeekCurrent
'Traverse queue.
While not msgMyMessage is Nothing
set msgMyMessage = qMyInputQueue.PeekNext
msgbox msgMyMessage.Label
Wend
qMyInputQueue.Reset 'Points to start of queue.
FormatName, Label, MSMQQuery, MSMQQueueInfo, MSMQQueueInfos, Next, Reset