matt2door
asked on
Write/Read to an AS400 DataQueue in VB.NET
Here is the code I've created. The problem I'm having is upon execution, I get and "unknown error" error message just after my message box for "about to write to dq". Not sure what I'm missing.
Private Sub btnDQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDQ.Click
' Add a reference to IBM AS/400 Client Access Express
' ActiveX Object Library
' (C:\Program Files\IBM\Client Acccess\Shared\cwbx.dll
On Error GoTo err_Enter
' Declare AS400 object
Dim oAS400 As cwbx.AS400System
' Declare Data Queue object
Dim oDTAQ As cwbx.DataQueue
' String objects for queue data
Dim sWriteString As String
Dim sReadString As String
' Create objects
oAS400 = New cwbx.AS400System
oDTAQ = New cwbx.DataQueue
' Define the AS400 by name - change value in quotes
oAS400.Define("SYS400")
' Supply user id and password for AS400
' Change values in quotes
oAS400.UserID = "M_USER"
oAS400.Password = "PASSWORD"
oAS400.Connect(cwbx.cwbcoS erviceEnum .cwbcoServ iceDataQue ues)
' Connect to Data Queue Service
MsgBox("about to connect")
oAS400.Connect(cwbx.cwbcoS erviceEnum .cwbcoServ iceDataQue ues)
' Define Data Queue object - change values in quotes
oDTAQ.LibraryName = "MATTDEV"
oDTAQ.QueueName = "MATTDQ"
' Write an entry to the data queue
sWriteString = "I wrote this string"
MsgBox("about to write to dq")
oDTAQ.Write(sWriteString)
' Read an entry from the data queue
MsgBox("READ FROM DQ")
sReadString = oDTAQ.Read(0)
' sReadString will now contain "I wrote this string"
MsgBox(sReadString)
GoTo err_end
err_Enter:
MsgBox(Err.Description)
err_end:
End Sub
Private Sub btnDQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDQ.Click
' Add a reference to IBM AS/400 Client Access Express
' ActiveX Object Library
' (C:\Program Files\IBM\Client Acccess\Shared\cwbx.dll
On Error GoTo err_Enter
' Declare AS400 object
Dim oAS400 As cwbx.AS400System
' Declare Data Queue object
Dim oDTAQ As cwbx.DataQueue
' String objects for queue data
Dim sWriteString As String
Dim sReadString As String
' Create objects
oAS400 = New cwbx.AS400System
oDTAQ = New cwbx.DataQueue
' Define the AS400 by name - change value in quotes
oAS400.Define("SYS400")
' Supply user id and password for AS400
' Change values in quotes
oAS400.UserID = "M_USER"
oAS400.Password = "PASSWORD"
oAS400.Connect(cwbx.cwbcoS
' Connect to Data Queue Service
MsgBox("about to connect")
oAS400.Connect(cwbx.cwbcoS
' Define Data Queue object - change values in quotes
oDTAQ.LibraryName = "MATTDEV"
oDTAQ.QueueName = "MATTDQ"
' Write an entry to the data queue
sWriteString = "I wrote this string"
MsgBox("about to write to dq")
oDTAQ.Write(sWriteString)
' Read an entry from the data queue
MsgBox("READ FROM DQ")
sReadString = oDTAQ.Read(0)
' sReadString will now contain "I wrote this string"
MsgBox(sReadString)
GoTo err_end
err_Enter:
MsgBox(Err.Description)
err_end:
End Sub
Hi, Matt2door
I played with this a little and got it to work in VBA. The changes are using StringConverter on strings to and from the data queue, plus setting the system name for the data queue.
Private Sub btnDQ_Click()
' Add a reference to IBM AS/400 Client Access Express
' ActiveX Object Library
' (C:\Program Files\IBM\Client Acccess\Shared\cwbx.dll
On Error GoTo err_Enter
' Declare AS400 object
Dim oAS400 As New cwbx.AS400System
' Declare Data Queue object
Dim oDTAQ As New cwbx.DataQueue
' Convert strings to array of bytes
Dim stringCvtr As New cwbx.StringConverter
' String objects for queue data
Dim sWriteString As String
Dim sReadString As String
' Define the AS400 by name - change value in quotes
oAS400.Define ("LAURA")
' Supply user id and password for AS400
' Change values in quotes
oAS400.UserID = "BH"
oAS400.Password = "BH"
oAS400.Connect (cwbx.cwbcoServiceEnum.cwb coServiceD ataQueues)
' Connect to Data Queue Service
MsgBox ("about to connect")
oAS400.Connect (cwbx.cwbcoServiceEnum.cwb coServiceD ataQueues)
' Define Data Queue object - change values in quotes
oDTAQ.LibraryName = "QGPL"
oDTAQ.QueueName = "BH"
Set oDTAQ.system = oAS400
' Write an entry to the data queue
sWriteString = "I wrote this string"
MsgBox ("about to write to dq")
oDTAQ.Write stringCvtr.ToBytes(sWriteS tring)
' Read an entry from the data queue
MsgBox ("READ FROM DQ")
sReadString = stringCvtr.FromBytes(oDTAQ .Read(0))
' sReadString will now contain "I wrote this string"
MsgBox (sReadString)
GoTo err_end
err_Enter:
MsgBox (Err.Description)
err_end:
End Sub
Hope this helps
bh
I played with this a little and got it to work in VBA. The changes are using StringConverter on strings to and from the data queue, plus setting the system name for the data queue.
Private Sub btnDQ_Click()
' Add a reference to IBM AS/400 Client Access Express
' ActiveX Object Library
' (C:\Program Files\IBM\Client Acccess\Shared\cwbx.dll
On Error GoTo err_Enter
' Declare AS400 object
Dim oAS400 As New cwbx.AS400System
' Declare Data Queue object
Dim oDTAQ As New cwbx.DataQueue
' Convert strings to array of bytes
Dim stringCvtr As New cwbx.StringConverter
' String objects for queue data
Dim sWriteString As String
Dim sReadString As String
' Define the AS400 by name - change value in quotes
oAS400.Define ("LAURA")
' Supply user id and password for AS400
' Change values in quotes
oAS400.UserID = "BH"
oAS400.Password = "BH"
oAS400.Connect (cwbx.cwbcoServiceEnum.cwb
' Connect to Data Queue Service
MsgBox ("about to connect")
oAS400.Connect (cwbx.cwbcoServiceEnum.cwb
' Define Data Queue object - change values in quotes
oDTAQ.LibraryName = "QGPL"
oDTAQ.QueueName = "BH"
Set oDTAQ.system = oAS400
' Write an entry to the data queue
sWriteString = "I wrote this string"
MsgBox ("about to write to dq")
oDTAQ.Write stringCvtr.ToBytes(sWriteS
' Read an entry from the data queue
MsgBox ("READ FROM DQ")
sReadString = stringCvtr.FromBytes(oDTAQ
' sReadString will now contain "I wrote this string"
MsgBox (sReadString)
GoTo err_end
err_Enter:
MsgBox (Err.Description)
err_end:
End Sub
Hope this helps
bh
i see that you're trying to connect two times, before msgbox, and after msgbox???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick response. Worked like a charm!
ftp://testcase.boulder.ibm.com/as400/fromibm/ApiSamples/
especially VBDATAQ.ZIP