Running the ActiveX Starter samples

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.

MQAX Starter samples for Microsoft Visual Basic Version 4 or later

This section explains how to run the MQAX starter samples for Microsoft Basic Version 4 or later.

Running the MQAXTRIV sample

  1. Start the queue manager.
  2. In Windows Explorer or File Manager, select the icon for the sample, MQAXTRIV.VBP (Visual Basic Project file) and open the file.

    The Visual Basic program starts and opens the file, MQAXTRIV.VBP.

  3. In Visual Basic, press function key 5 (F5) to run the sample.
  4. Click anywhere in the window form, "MQAX trivial tester".

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

Starting the MQAXCLSS sample

This sample allows you to browse properties and methods of queue managers and queue objects.

  1. Start the queue manager.
  2. Open the file, MQAXCLSS.VBP, by double clicking on the document icon in Windows Explorer or by choosing File - Open from the file menu in Visual Basic.
  3. Start the sample.
  4. Enter the appropriate queue manager and queue names then click the corresponding buttons.

The MQAXDLST sample

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.

MQAX Starter sample for Microsoft Excel 95 or later

This section explains how to run the MQAX starter sample for Microsoft Excel 95 or later, MQAXTRIV.XLS.

Running the MQAXTRIV.XLS sample

  1. Start the queue manager.
  2. In Explorer or File Manager, select the icon for the MQAX sample MQAXTRIV.XLS.
  3. Click on the button.
  4. The screen will be updated with a success (or failure) message.

Running the Bank demonstration with MQAX.XLS

  1. Start the queue manager.
  2. Run the WebSphere MQ MQSC command file, BANK.TST. This sets up the necessary WebSphere MQ queue definitions.

    To find out how to use an MQSC command file, refer to the WebSphere MQ System Administration Guide book.

  3. Run MQAXBSRV.VBP. This is the server, simulating a back-end application. This has to run in conjunction with Microsoft Excel.
  4. Run MQAX.XLS. This is the client WebSphere MQ demonstration.
  5. Select a customer from the drop-down list box.
  6. Click on the Submit button.

After a short time, (3 seconds or so) the fields should become populated with values and you should see a bar chart appear.

Starter sample using an ActiveX compatible WWW browser

Note:
To run this sample, you must be running an ActiveX compatible Web browser. Microsoft Internet Explorer (but not Netscape Navigator) is a compatible Web browser.

Running the HTML sample

This sample demonstrates how you can invoke MQAX from both VBScript and JavaScript.

  1. Start the queue manager.
  2. Open the file, "MQAXTRIV.HTM", in your ActiveX compatible Web browser.

    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.

  3. Follow the instructions on the screen.


© IBM Corporation 2002. All Rights Reserved