Sending a Date in a Message

Sending messages consists of opening a queue with send access, creating the message, calling the Send method, and then closing the queue. The following procedure and example code show how this is done when sending a message whose body contains a Date type.

    To send a Date in a message
  1. Declare QueueInfo, Queue, and Message objects. This example uses one set of Queue and Message objects for sending the message and another set of Queue and Message objects for receiving the message.
    Dim qinfo As New MSMQQueueInfo
    Dim qSend As MSMQQueue
    Dim qReceive As MSMQQueue
    Dim mSend As New MSMQMessage
    Dim mReceive As MSMQMessage
     
  2. Create a destination queue and open it with send access. This example creates a public queue on the local computer.
    qinfo.PathName = ".\SendTest"
    qinfo.Label = "Send Message Test"
    On Error Resume Next          'Ignore if queue already exists.
    qinfo.Create
    On Error GoTo 0
    Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
     
  3. Send the message with a Date body type.
    mSend.Label = "Date Message"
    mSend.Body = Date
    mSend.Send qSend
    qSend.Close
     
  4. Open the destination queue with receive access and retrieve the message. This example removes the message from the queue.
    Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
    Set mReceive = qReceive.Receive
    qReceive.Close
     
  5. Verify that the body of the retrieved message is a Date type.
    If TypeName(mReceive.Body) = "Date" Then
       MsgBox "The retrieved message body is a Date type."
       Else
       MsgBox "The retrieved message body is not a Date type."
    End If
     

Example Code

The following example creates a destination queue, sends a message whose body contains a Date, retrieves the message, and tests the retrieved message body to see if it is a Date type.

Option Explicit

Dim qinfo As New MSMQQueueInfo
Dim qSend As MSMQQueue
Dim qReceive As MSMQQueue
Dim mSend As New MSMQMessage
Dim mReceive As MSMQMessage

Private Sub Form_Click()
  
  '*************************************************************
  ' Create a destination queue and open it with SEND access.
  '*************************************************************
  qinfo.PathName = ".\SendTest"
  qinfo.Label = "Send Message Test"
  On Error Resume Next          'Ignore if queue already exists.
  qinfo.Create
  On Error GoTo 0
  Set qSend = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)
  
  '*************************************************************
  ' Send message with Date body type.
  '*************************************************************
  mSend.Label = "Date Message"
  mSend.Body = Date
  mSend.Send qSend
  qSend.Close
    
  '*************************************************************
  ' Open the destination queue with Receive access and
  ' retrieve the message. The retrieved message body is tested
  ' to verify it is a Date type.
  '*************************************************************
  Set qReceive = qinfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)
  Set mReceive = qReceive.Receive
  qReceive.Close
  
  If TypeName(mReceive.Body) = "Date" Then
     MsgBox "The retrieved message body is a Date type."
     Else
     MsgBox "The retrieved message body is not a Date type."
  End If
  
End Sub