|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Null pointer error GETting messages from a queue in... VBA |
« View previous topic :: View next topic » |
Author |
Message
|
bathouin |
Posted: Mon Apr 02, 2007 9:34 am Post subject: Null pointer error GETting messages from a queue in... VBA |
|
|
Newbie
Joined: 02 Apr 2007 Posts: 3 Location: Switzerland
|
Hi
I'm trying to use MQ from a MS Access application. I worked long time ago with MQ under VMS, so I'm not new to the concept, but certainly to the details under Windows XP and VBA... I succeeded in connecting to a QManager, to open the default queue, and to PUT messages in that queue. However, when I try to read the messages that I have put in the queue, I invariably get an MQRC_NULL_POINTER error, and I have no idea why. Here is my very simple code:
Public Sub GETMessages()
Dim qManager As New MQQueueManager
Dim q As MQQueue
Dim qMsg As MQMessage
Dim sTemp As String
Call ConnectToQMan("", qManager)
Call OpenQueueForRead(qManager, "default", q)
sTemp = "A"
While sTemp <> ""
Call GetQueue(q, qMsg)
sTemp = qMsg.MessageData
If sTemp = "" Then Exit Sub
Debug.Print sTemp
Wend
End Sub
Public Sub OpenQueueForRead(qManager As MQQueueManager, qName As String, q As MQQueue)
Set q = qManager.AccessQueue(qName, MQOO_INPUT_SHARED + MQOO_BROWSE)
q.Open
End Sub
Public Sub GetQueue(q As MQQueue, qMsg As MQMessage)
Dim gmo As MQGetMessageOptions
Set gmo = New MQGetMessageOptions
gmo.Options = MQGMO_WAIT
gmo.WaitInterval = MQWI_UNLIMITED
q.Get qMsg, gmo
End Sub
I'd be very grateful for any hints about what could be wrong.
Thanks
Bernard |
|
Back to top |
|
 |
yortch |
Posted: Mon Apr 02, 2007 9:52 am Post subject: |
|
|
Apprentice
Joined: 30 Aug 2004 Posts: 34
|
I think you need to initialize the mqmessage instance before trying to get it. Try:
Code: |
Set qMsg = New MQMessage
Call GetQueue(q, qMsg)
|
|
|
Back to top |
|
 |
bathouin |
Posted: Mon Apr 02, 2007 10:20 am Post subject: |
|
|
Newbie
Joined: 02 Apr 2007 Posts: 3 Location: Switzerland
|
yortch wrote: |
I think you need to initialize the mqmessage instance before trying to get it. Try:
Code: |
Set qMsg = New MQMessage
Call GetQueue(q, qMsg)
|
|
YES, brilliant, it works.
HOWEVER, on the LAST message (which of course is the only one I'm interested in...), the q.Get never returns ! The hourglass comes up, and nothing happens !? What can that be due to ? How can I avoid that behavious anyway ?
Regards
bernard |
|
Back to top |
|
 |
yortch |
Posted: Mon Apr 02, 2007 10:38 am Post subject: |
|
|
Apprentice
Joined: 30 Aug 2004 Posts: 34
|
That's because you have your code to wait indefinitely, you should set a small wait interval, which if you do, you'll need to catch an exception thrown when there are no more messages in the queue. Or you could check the queue depth instead. |
|
Back to top |
|
 |
bathouin |
Posted: Mon Apr 02, 2007 10:46 am Post subject: |
|
|
Newbie
Joined: 02 Apr 2007 Posts: 3 Location: Switzerland
|
yortch wrote: |
That's because you have your code to wait indefinitely, you should set a small wait interval, which if you do, you'll need to catch an exception thrown when there are no more messages in the queue. Or you could check the queue depth instead. |
Yes, I change my _WAIT to NO_WAIT and my WaitInterval to 1000. I saw somewhere how I can trap the MQ Exceptions, now I don't find it anymore. Can you help me there ?
Thanks
Bernard |
|
Back to top |
|
 |
yortch |
Posted: Mon Apr 02, 2007 11:50 am Post subject: |
|
|
Apprentice
Joined: 30 Aug 2004 Posts: 34
|
This isn't VB .NET, is it? If it is, you need a try/catch clause, otherwise something like: "On Error Resume Next"
The "MQ API Support" may be a better place to find answers to these questions: http://www.mqseries.net/phpBB2/viewforum.php?f=6 |
|
Back to top |
|
 |
Michael Dag |
Posted: Mon Apr 02, 2007 12:03 pm Post subject: |
|
|
 Jedi Knight
Joined: 13 Jun 2002 Posts: 2607 Location: The Netherlands (Amsterdam)
|
bathouin wrote: |
yortch wrote: |
That's because you have your code to wait indefinitely, you should set a small wait interval, which if you do, you'll need to catch an exception thrown when there are no more messages in the queue. Or you could check the queue depth instead. |
Yes, I change my _WAIT to NO_WAIT and my WaitInterval to 1000. I saw somewhere how I can trap the MQ Exceptions, now I don't find it anymore. Can you help me there ?
Thanks
Bernard |
check the value of GetQueue.CompletionCode and GetQueue.ReasonCode _________________ Michael
MQSystems Facebook page |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Apr 02, 2007 12:06 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Also, I think when you set the MQGMO to NO_WAIT, you told it to ignore your WaitInterval. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|