Help with VBA macro to connect to PCOMM(Mainframe session)

techie89

New Member
Joined
Mar 16, 2013
Messages
2
Hi,
Iam trying to automate a certain process in mainframes.
Initially, I wrote a macro to connect to PComm using the IBM link: http://publib.boulder.ibm.com/infocenter/pcomhelp/v5r9/index.jsp?topic=/com.ibm.pcomm.doc/books/html/host_access08.htm
The macro opens a Pcomm session.
But, 1. Iam unable to use the settext method to type in the mainframe screen.It does'nt work
2.When i try to retrieve the cursor position, it returns the position (1,1) though the actual position is (3,15)
3.The inputinhibit method used below returns 'Communication check'. I need to get 'Not Inhibited' instead
Please have a look at my code below, and let me know where I might be wrong, or could have missed something.
Is the macro not able to connect?

Also let me know if further details are required.
Thanks,

CODE:
Sub step()
'Connect Macro

' Application.Goto Reference:="connect"
ChDir "C:\Documents and Settings\sr123\Desktop"
'ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\sr123\Desktop\cktmac.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

'Object declaration
Dim Mgr As Object
Dim Num As Long
Dim autECLOIA As Object
Dim autECLPSObj As Object
Dim autECLConnList As Object
Dim CurPosRow As Long
Dim CurPosCol As Long
Dim SessObj As Object

'object creation
Set Mgr = CreateObject("PCOMM.autECLConnMgr")
Num = Mgr.autECLConnList.Count
Set autECLOIA = CreateObject("PCOMM.autECLOIA")
Set autECLPSObj = CreateObject("PCOMM.autECLPS")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set SessObj = CreateObject("PCOMM.autECLSession")


'setting connections
autECLOIA.SetConnectionByName ("B")
autECLPSObj.SetConnectionByName ("C")
SessObj.SetConnectionByName ("D")
autECLConnList.SetConnectionByName ("E")


'start a new connection
Mgr.StartConnection ("profile=a74ism.WS connname=A")


'Checking whether connected
TestConnection
startcommunication
autECLOIA.WaitForInputReady (7000)
autECLConnList.Refresh


'Checking for input inhibit

If autECLOIA.InputInhibited = 0 Then MsgBox "Not Inhibited "

If autECLOIA.InputInhibited = 1 Then MsgBox "System Wait "

If autECLOIA.InputInhibited = 2 Then MsgBox "Communication Check "

If autECLOIA.InputInhibited = 3 Then MsgBox "Program Check "

If autECLOIA.InputInhibited = 4 Then MsgBox "Machine Check "

If autECLOIA.InputInhibited = 5 Then MsgBox "Other Inhibit "


'CURSOR POSITION CHECKING

CurPosRow = autECLPSObj.CursorPosRow

CurPosCol = autECLPSObj.CursorPosCol

MsgBox " ROW= " & CurPosRow

MsgBox " COL= " & CurPosCol

autECLPSObj.settext "A74ISM", 3, 15


MsgBox "crossed"

End Sub

*********************************************************************
(The main code ends here.. the below two code blocks are being called in the above program)




Sub TestConnection()

Dim Hand As Long
Dim Obj As Object

Set Obj = CreateObject("PCOMM.autECLOIA")

' Initialize the connection
Obj.SetConnectionByName ("A")

Do
Obj.WaitForInputReady (2500)
Loop While (Obj.Started = "False")

If Obj.Started = "True" Then
MsgBox "Started"
Else
MsgBox "Not - Started"
End If

End Sub


Sub startcommunication()

Dim PSObj As Object
Dim autECLConnList As Object

Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set PSObj = CreateObject("PCOMM.autECLPS")

' Initialize the session
autECLConnList.Refresh
PSObj.SetConnectionByHandle (autECLConnList(1).Handle)

PSObj.startcommunication

End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hello,

I know it's been a while but did you figure out your issue? If not could I ask the version of windows and the version of PComm you are using?

Hi,
Iam trying to automate a certain process in mainframes.
Initially, I wrote a macro to connect to PComm using the IBM link: http://publib.boulder.ibm.com/infocenter/pcomhelp/v5r9/index.jsp?topic=/com.ibm.pcomm.doc/books/html/host_access08.htm
The macro opens a Pcomm session.
But, 1. Iam unable to use the settext method to type in the mainframe screen.It does'nt work
2.When i try to retrieve the cursor position, it returns the position (1,1) though the actual position is (3,15)
3.The inputinhibit method used below returns 'Communication check'. I need to get 'Not Inhibited' instead
Please have a look at my code below, and let me know where I might be wrong, or could have missed something.
Is the macro not able to connect?

Also let me know if further details are required.
Thanks,

CODE:
Sub step()
'Connect Macro

' Application.Goto Reference:="connect"
ChDir "C:\Documents and Settings\sr123\Desktop"
'ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\sr123\Desktop\cktmac.xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

'Object declaration
Dim Mgr As Object
Dim Num As Long
Dim autECLOIA As Object
Dim autECLPSObj As Object
Dim autECLConnList As Object
Dim CurPosRow As Long
Dim CurPosCol As Long
Dim SessObj As Object

'object creation
Set Mgr = CreateObject("PCOMM.autECLConnMgr")
Num = Mgr.autECLConnList.Count
Set autECLOIA = CreateObject("PCOMM.autECLOIA")
Set autECLPSObj = CreateObject("PCOMM.autECLPS")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set SessObj = CreateObject("PCOMM.autECLSession")


'setting connections
autECLOIA.SetConnectionByName ("B")
autECLPSObj.SetConnectionByName ("C")
SessObj.SetConnectionByName ("D")
autECLConnList.SetConnectionByName ("E")


'start a new connection
Mgr.StartConnection ("profile=a74ism.WS connname=A")


'Checking whether connected
TestConnection
startcommunication
autECLOIA.WaitForInputReady (7000)
autECLConnList.Refresh


'Checking for input inhibit

If autECLOIA.InputInhibited = 0 Then MsgBox "Not Inhibited "

If autECLOIA.InputInhibited = 1 Then MsgBox "System Wait "

If autECLOIA.InputInhibited = 2 Then MsgBox "Communication Check "

If autECLOIA.InputInhibited = 3 Then MsgBox "Program Check "

If autECLOIA.InputInhibited = 4 Then MsgBox "Machine Check "

If autECLOIA.InputInhibited = 5 Then MsgBox "Other Inhibit "


'CURSOR POSITION CHECKING

CurPosRow = autECLPSObj.CursorPosRow

CurPosCol = autECLPSObj.CursorPosCol

MsgBox " ROW= " & CurPosRow

MsgBox " COL= " & CurPosCol

autECLPSObj.settext "A74ISM", 3, 15


MsgBox "crossed"

End Sub

*********************************************************************
(The main code ends here.. the below two code blocks are being called in the above program)




Sub TestConnection()

Dim Hand As Long
Dim Obj As Object

Set Obj = CreateObject("PCOMM.autECLOIA")

' Initialize the connection
Obj.SetConnectionByName ("A")

Do
Obj.WaitForInputReady (2500)
Loop While (Obj.Started = "False")

If Obj.Started = "True" Then
MsgBox "Started"
Else
MsgBox "Not - Started"
End If

End Sub


Sub startcommunication()

Dim PSObj As Object
Dim autECLConnList As Object

Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set PSObj = CreateObject("PCOMM.autECLPS")

' Initialize the session
autECLConnList.Refresh
PSObj.SetConnectionByHandle (autECLConnList(1).Handle)

PSObj.startcommunication

End Sub
 
Upvote 0
Hi,
I have'nt figured out the issue yet..That version of PCOMM must be old, and windows was certainly older than version 7.I have a different computer now, n so i cant get the version details. Do u think the problem was due to the versions? Is the code I used right?
 
Upvote 0
There is an issue when running Windows 7 and Pcomm version v6.0.5 and below. (it gets spotty depending on the 5.X version) It was something that was corrected in v6.0.6 and above so I'm guessing that you propably had an older version of PComm that had the connunication issue.

Hi,
I have'nt figured out the issue yet..That version of PCOMM must be old, and windows was certainly older than version 7.I have a different computer now, n so i cant get the version details. Do u think the problem was due to the versions? Is the code I used right?
 
Upvote 0
Code:
:

[COLOR=#0000ff]'setting connections[/COLOR]
autECLOIA.SetConnectionByName ("B")
autECLPSObj.SetConnectionByName ("C")
SessObj.SetConnectionByName ("D")
autECLConnList.SetConnectionByName ("E")

[COLOR=#0000ff]'start a new connection[/COLOR]
Mgr.StartConnection ("profile=a74ism.WS connname=A")


I think you have to use the same name, you can't skip from A to E, they should all be the same name for the same session.
 
Upvote 0
Hi All,

yeah gcraill is right, I am writing advanced macros from within excel to steer my company's AS400 terminal windows and as I've managed to steer multiple sessions through vbscript from a HTA file (www code but as windows app), I was not able to do the same from within an excel vba macro. Sadly I've looked through every documentation file and help on the net - I'm doing it for at least 3 years now. It is not working. So your solution would be to cut your code to:

Code:
[COLOR=#333333]Sub step()[/COLOR]
[COLOR=#333333]'Connect Macro[/COLOR]

[COLOR=#333333]' Application.Goto Reference:="connect"[/COLOR]
[COLOR=#333333]ChDir "C:\Documents and Settings\sr123\Desktop"[/COLOR]
[COLOR=#333333]'ActiveWorkbook.SaveAs Filename:= _[/COLOR]
[COLOR=#333333]"C:\Documents and Settings\sr123\Desktop\cktmac.xlsm", FileFormat:= _[/COLOR]
[COLOR=#333333]xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False[/COLOR]

[COLOR=#0000FF]'Object declaration[/COLOR]
[COLOR=#333333]'Dim Mgr As Object                'you don't need ConnMgr if using ECLSession[/COLOR]
[COLOR=#333333]'Dim Num As Long[/COLOR]
[COLOR=#333333]Dim autECLOIA As Object[/COLOR]
[COLOR=#333333]Dim autECLPSObj As Object[/COLOR][COLOR=#333333]
[/COLOR][COLOR=#333333]Dim CurPosRow As Long         'long is to long - the AS400 terminal window has mainly max 132 characters - you don't need such a big number for this variable - takes to much memory[/COLOR]
[COLOR=#333333]Dim CurPosCol As Long           [/COLOR][COLOR=#333333]'long is to long - the AS400 terminal window has mainly max 132 characters - you don't need such a big number for this variable - takes to much memory[/COLOR]
[COLOR=#333333]Dim SessObj As Object     'this is your session definition[/COLOR]

[COLOR=#0000ff]'object creation[/COLOR]
[COLOR=#333333]'Set Mgr = CreateObject("PCOMM.autECLConnMgr")    'in my opinon not needed, I'm not using it in VBA excel[/COLOR]
[COLOR=#333333]'Num = Mgr.autECLConnList.Count             'if you use only one session this is also not needed[/COLOR]
[COLOR=#333333]Set autECLOIA = CreateObject("PCOMM.autECLOIA")[/COLOR]
[COLOR=#333333]Set autECLPSObj = CreateObject("PCOMM.autECLPS")[/COLOR]
[COLOR=#333333]'Set autECLConnList = CreateObject("PCOMM.autECLConnList")     'not needed, as above[/COLOR]
[COLOR=#333333]Set SessObj = CreateObject("PCOMM.autECLSession")[/COLOR]


[COLOR=#0000ff]'setting connections[/COLOR]
[COLOR=#333333]autECLOIA.SetConnectionByName ("B")   'wrong because here you say the script from where to get the OIA info i.e. the X session block - but you are pointing the wrong session[/COLOR]
[COLOR=#333333]'autECLPSObj.SetConnectionByName ("C")   'not needed, because all commands like input text would be executed here - wrong session ID[/COLOR]
[COLOR=#333333]SessObj.SetConnectionByName ("D")  'use [/COLOR][COLOR=#333333]your session ID [/COLOR][COLOR=#333333]"A/B/C/D/whatever" or create a VBA excel form to ask which session to choose - can export you my if it helps[/COLOR]
[COLOR=#333333]'autECLConnList.SetConnectionByName ("E") 'not needed as it is contrary to [/COLOR][COLOR=#333333]SessObj.SetConnectionByName("D") pointing other session ID[/COLOR]


[HTML]'from this posiiton on I would write it somewhere different, but try to figure it out how to shorten your code, if you'll have some more questions ask, today I was searching for something, but have to have a function ready for tomorrow morning so have to go back - the rest is generally ok, but I'm checkin for OIA errors as error handling procedure in VBA in loops, not before the procedure itself - but your code will work if you figure out how to get the correct OIA msg's from the session you are working with - and only one from Excel
[/HTML]
[COLOR=#0000ff]'start a new connection[/COLOR]
[COLOR=#333333]'Mgr.StartConnection ("profile=a74ism.WS connname=A")  'don;t know the content of [/COLOR][COLOR=#333333]a74ism.WS, but my sessions are already started at begin of the day, so... I'm not using VBA to start sessions[/COLOR]


[COLOR=#0000ff]'Checking whether connected[/COLOR]
[COLOR=#333333]TestConnection              [/COLOR][COLOR=#333333]'here you're referring to a sub where you're starting the communication with [/COLOR][COLOR=#333333]A session[/COLOR]
[COLOR=#333333]startcommunication        'here you again try to start communication this time with the first session but through another handler - make it easier - cut the code - I wish you look, because I see you are on the right track[/COLOR]
[COLOR=#333333]autECLOIA.WaitForInputReady (7000)[/COLOR]
[COLOR=#333333]autECLConnList.Refresh[/COLOR]


[COLOR=#0000ff]'Checking for input inhibit[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 0 Then MsgBox "Not Inhibited "[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 1 Then MsgBox "System Wait "[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 2 Then MsgBox "Communication Check "[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 3 Then MsgBox "Program Check "[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 4 Then MsgBox "Machine Check "[/COLOR]

[COLOR=#333333]If autECLOIA.InputInhibited = 5 Then MsgBox "Other Inhibit "[/COLOR]


[COLOR=#0000ff]'CURSOR POSITION CHECKING[/COLOR]

[COLOR=#333333]CurPosRow = autECLPSObj.CursorPosRow[/COLOR]

[COLOR=#333333]CurPosCol = autECLPSObj.CursorPosCol[/COLOR]

[COLOR=#333333]MsgBox " ROW= " & CurPosRow[/COLOR]

[COLOR=#333333]MsgBox " COL= " & CurPosCol[/COLOR]

[COLOR=#333333]autECLPSObj.settext "A74ISM", 3, 15[/COLOR]


[COLOR=#333333]MsgBox "crossed"[/COLOR]

[COLOR=#333333]End Sub[/COLOR]

[COLOR=#333333]*********************************************************************[/COLOR]
[COLOR=#333333](The main code ends here.. the below two code blocks are being called in the above program) [/COLOR]




[COLOR=#333333]Sub TestConnection()[/COLOR]

[COLOR=#333333]Dim Hand As Long[/COLOR]
[COLOR=#333333]Dim Obj As Object[/COLOR]

[COLOR=#333333]Set Obj = CreateObject("PCOMM.autECLOIA")[/COLOR]

[COLOR=#333333]' Initialize the connection[/COLOR]
[COLOR=#333333]Obj.SetConnectionByName ("A")                  
[/COLOR]
[COLOR=#333333]Do[/COLOR]
[COLOR=#333333]Obj.WaitForInputReady (2500)[/COLOR]
[COLOR=#333333]Loop While (Obj.Started = "False")[/COLOR]

[COLOR=#333333]If Obj.Started = "True" Then[/COLOR]
[COLOR=#333333]MsgBox "Started"[/COLOR]
[COLOR=#333333]Else[/COLOR]
[COLOR=#333333]MsgBox "Not - Started"[/COLOR]
[COLOR=#333333]End If[/COLOR]

[COLOR=#333333]End Sub[/COLOR]


[COLOR=#333333]Sub startcommunication()[/COLOR]

[COLOR=#333333]Dim PSObj As Object[/COLOR]
[COLOR=#333333]Dim autECLConnList As Object[/COLOR]

[COLOR=#333333]Set autECLConnList = CreateObject("PCOMM.autECLConnList")[/COLOR]
[COLOR=#333333]Set PSObj = CreateObject("PCOMM.autECLPS")[/COLOR]

[COLOR=#333333]' Initialize the session[/COLOR]
[COLOR=#333333]autECLConnList.Refresh[/COLOR]
[COLOR=#333333]PSObj.SetConnectionByHandle (autECLConnList(1).Handle)[/COLOR]

[COLOR=#333333]PSObj.startcommunication[/COLOR]

[COLOR=#333333]End Sub[/COLOR]

Sorry for being to harsh, didin't mean too. I'll come back here to look where you came to. Promise.
 
Upvote 0

Forum statistics

Threads
1,225,146
Messages
6,183,162
Members
453,148
Latest member
yevhen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top