Before you run the WebSphere MQ Automation Classes for ActiveX Starter samples check that you have a default queue manager running and that you have created the required queue definitions. For details of creating and running a queue manager and creating a queue, refer to WebSphere MQ System Administration Guide. The sample uses the queue SYSTEM.DEFAULT.LOCAL.QUEUE which should be defined on any normally set up WebSphere MQ server.
This section explains how to run the MQAX starter samples for Microsoft Basic Version 4 or later.
The Visual Basic program starts and opens the file, MQAXTRIV.VBP.
If everything is working correctly, the window background should change to green. If there is a problem with your setup, the window background should change to red and error information will be displayed.
The central part of the Visual Basic sample is shown below.
Option Explicit
Private Sub Form_Click()
'*******************************************************************************
'* This simple example illustrates how to put and get a WebSphere MQ message to
'* and from an WebSphere MQ message queue. The data from the message returned by the
'*get is read and compared with that from the original message.
'*******************************************************************************
Dim MQSess As MQSession '* session object
Dim QMgr As MQQueueManager '* queue manager object
Dim Queue As MQQueue '* queue object
Dim PutMsg As MQMessage '* message object for put
Dim GetMsg As MQMessage '* message object for get
Dim PutOptions As MQPutMessageOptions '* get message option
Dim GetOptions As MQGetMessageOptions '* put message options
Dim PutMsgStr As String '* put message data string
Dim GetMsgStr As String '* get message data string
'*******************************************************************************
'* Handle errors
'*******************************************************************************
On Error GoTo HandleError
'*******************************************************************************
'* Initialize the current position for the form
'*******************************************************************************
CurrentX = 0
CurrentY = 0
'*******************************************************************************
'* Create the MQSession object and access the MQQueueManager and (local) MQQueue
'*******************************************************************************
Set MQSess = New MQSession
Set QMgr = MQSess.AccessQueueManager("")
Set Queue = QMgr.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", _
MQOO_OUTPUT Or MQOO_INPUT_AS_Q_DEF)
'*******************************************************************************
'* Create a new MQMessage object for use with put, add some data then create an
'* MQPutMessageOptions object and put the message
'*******************************************************************************
Set PutMsg = MQSess.AccessMessage()
PutMsgStr = "12345678 " & Time
PutMsg.MessageData = PutMsgStr
Set PutOptions = MQSess.AccessPutMessageOptions()
Queue.Put PutMsg, PutOptions
'*******************************************************************************
'* Create a new MQMessage object for use with get, set the MessageId (to that of
'* the message that was put), create an MQGetMessageOptions object and get the
'* message.
'*
'* Note: Setting the MessageId ensures that the get returns the MQMessage
'* that was put earlier.
'*******************************************************************************
Set GetMsg = MQSess.AccessMessage()
GetMsg.MessageId = PutMsg.MessageId
Set GetOptions = MQSess.AccessGetMessageOptions()
Queue.Get GetMsg, GetOptions
'*******************************************************************************
'* Read the data from the message returned by the get, compare it with
'* that from the original message and output a suitable message.
'*******************************************************************************
GetMsgStr = GetMsg.MessageData
Cls
If GetMsgStr = PutMsgStr Then
BackColor = RGB(127, 255, 127) '* set to green for ok
Print
Print "Message data comparison was successful."
Print "Message data: """ & GetMsgStr & """"
Else
BackColor = RGB(255, 255, 127) '* set to amber for compare error
Print "Compare error: "
Print "The message data returned by the get did not match the " &_
"input data from the original message that was put."
Print
Print "Input message data: """ & PutMsgStr & """"
Print "Returned message data: """ & GetMsgStr & """"
End If
Exit Sub
'*******************************************************************************
'* Handle errors
'*******************************************************************************
HandleError:
Dim ErrMsg As String
Dim StrPos As Integer
Cls
BackColor = RGB(255, 0, 0) '* set to red for error
Print "An error occurred as follows:"
Print ""
If MQSess.CompletionCode <> MQCC_OK Then
ErrMsg = Err.Description
StrPos = InStr(ErrMsg, " ") '* search for first blank
If StrPos > 0 Then
Print Left(ErrMsg, StrPos) '* print offending MQAX object name
Else
Print Error(Err) '* print complete error object
End If
Print ""
Print "WebSphere MQ Completion Code = " & MQSess.CompletionCode
Print "WebSphere MQ Reason Code = " & MQSess.ReasonCode
Print "(" & MQSess.ReasonName & ")"
Else
Print "Visual Basic error: " & Err
Print Error(Err)
End If
Exit Sub
End Sub
This sample allows you to browse properties and methods of queue managers and queue objects.
The Visual Basic MQAXDLST sample demonstrates the use of a distribution list to send the same message to two queues with one put. To run the sample, do the same as for the MQAXCLSS sample above.
This section explains how to run the MQAX starter sample for Microsoft Excel 95 or later, MQAXTRIV.XLS.
To find out how to use an MQSC command file, refer to the WebSphere MQ System Administration Guide book.
After a short time, (3 seconds or so) the fields should become populated with values and you should see a bar chart appear.
This sample demonstrates how you can invoke MQAX from both VBScript and JavaScript.
You can do this either by double-clicking the file icon in Windows Explorer or you can choose File - Open from the File menu of your ActiveX compatible Web browser.