The following programming tips are provided for those new to writing MSMQ or Microsoft® Visual Basic® applications. They highlight several issues that may make writing your MSMQ application a bit easier.
Dim qDest As MSMQQueue 'Set command needed. Dim msgSent As New MSMQMessage Dim msgDest As MSMQMessage 'Peek method returns 'MSMQMessage instance. Set qDest = qinfoDest.Open(MQ_SEND_ACCESS, MQ_DENY_NONE) msgSent.Send qDest Set qDest = qinfoDest.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE) Set msgDest = qDest.Peek(ReceiveTimeout:=100)
When functions and subroutines are called, parentheses are sometimes required and sometimes not.
When functions or subroutines are called explicitly using the Call keyword, parentheses are required whenever there is one or more arguments. (The return value of a function can be ignored.)
For example:
Call Foo(x) Call Foo(1, 2)
When a function is called and the return value is used, parentheses are always required whenever there is one or more arguments.
For example:
y = Foo(x, z) ' Result of Foo used to assign to y. Call Bar(Foo(1)) ' Result of Foo used as argument to Bar.
However, when a function or subroutine is called without using the Call keyword and its return value is ignored:
For example:
Foo x 'Parentheses cannot be used: x is passed by reference. Foo (x) 'x is effectively passed by value.
Create IsWorldReadable:=True, IsTransactional:=False Create False, True
dim qinfo as MSMQQueueInfo set qinfo = New MSMQQueueInfo qinfo.PathName = ".\PRIVATE$\CreateTest" qinfo.Create dim qinfo as Object set qinfo = New MSMQQueueInfo qinfo.PathName = ".\PRIVATE$\CreateTest" qinfo.Create
Dim strId As String Dim myapp As New MSMQApplication strId = MachineIdOfMachineName("machinename") Debug.Print strId strId = MSMQApplication.MachineIdOfMachineName("machinename") Debug.Print strId strId = myapp.MachineIdOfMachineName("machinename") Debug.Print strId