From: Doug Howell on
I have a script that opens a terminal session for an IBM AS/400 system
and performs a series of keystrokes.

The script works great, except if there is/are already session(s)
opened by the user.

The terminal sessions are lettered A, B, C, etc as multiple sessions
are opened by a user.

I guess I need to some how have the script determine what the session
letter is for the one it just opened so that it uses that session
instance instead of always using session A. (which is what my code
does now)

I'm not exactly sure how to do this.


Here is the existing code:

Sub Run(ByVal sFile)
Dim shell

Set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & sFile & Chr(34), 1, false
Set shell = Nothing
End Sub
'
Run "\\Dcc-1\dcc scada\AS400.ws"

Dim SessObj 'As Object
Set SessObj = CreateObject("PCOMM.autECLSession")

' Initialize the session
SessObj.SetConnectionByName ("A")

Function fwaitforappavailable(SessionID)

Dim autECLOIAObj 'As Object

Set autECLOIAObj = CreateObject("PCOMM.autECLOIA")
autECLOIAObj.SetConnectionByName (SessionID)

If (autECLOIAObj.waitforappavailable(10000)) Then
MsgBox "Click OK to continue."
Else
MsgBox "Timeout Occured when waiting for the application to
become available"
End If

End Function


Function fwaitforinputready(SessionID)

Dim autECLOIAObj 'As Object

Set autECLOIAObj = CreateObject("PCOMM.autECLOIA")
autECLOIAObj.SetConnectionByName (SessionID)

If (autECLOIAObj.waitforinputready(10000)) Then
'MsgBox "Ready for input"
Else
MsgBox "Timeout Occurred when waiting for the application to
accept input"
End If

End Function


Function fsendkeys(keyinput)

Dim autECLPSObj 'As Object
Dim autECLConnList 'As Object
Set autECLPSObj = CreateObject("PCOMM.autECLPS")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")

' Initialize the connection
autECLConnList.Refresh
autECLPSObj.SetConnectionByHandle (autECLConnList(1).Handle)
autECLPSObj.sendkeys keyinput

End Function


Function fwaitforattrib(SessionID, row, col, waitdata, MaskData,
Plane)

Dim autECLPSObj 'As Object

Set autECLPSObj = CreateObject("PCOMM.autECLPS")
autECLPSObj.SetConnectionByName (SessionID)

If (autECLPSObj.WaitForAttrib(row, col, waitdata, MaskData, Plane,
10000)) Then
'MsgBox "Attribute " & waitdata & " found"
Else
MsgBox "Timeout Occurred when waiting for Attribute"
End If


End Function


Function fwaitforcursor(SessionID, row, col)

Dim autECLPSObj 'As Object

Set autECLPSObj = CreateObject("PCOMM.autECLPS")
autECLPSObj.SetConnectionByName (SessionID)

If (autECLPSObj.waitforcursor(row, col, 10000)) Then
'MsgBox "Cursor is at " & row & "," & col
Else
MsgBox "Timeout Occurred when waiting for cursor"
End If


End Function


Function fsetcursorpos(row, col)


Dim autECLPSObj 'As Object
Dim autECLConnList 'As Object
Set autECLPSObj = CreateObject("PCOMM.autECLPS")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")

' Initialize the connection with the first in the list
autECLConnList.Refresh
autECLPSObj.SetConnectionByHandle (autECLConnList(1).Handle)
autECLPSObj.setcursorpos row, col

End Function


'REM This line calls the macro subroutine
subSub1_

sub subSub1_()
fwaitforappavailable ("A")

fwaitforinputready ("A")
fsendkeys "dccscada"
fwaitforinputready ("A")
fsendkeys "[tab]"
fwaitforinputready ("A")
fsendkeys "dccscada"
fwaitforinputready ("A")
fsendkeys "[enter]"

'fwaitforattrib "A",1,"20","3c",3,10000

'fwaitforappavailable ("A")

fwaitforinputready ("A")
fsendkeys "[enter]"

'fwaitforattrib "A",13,"00","3c",3,10000

'fwaitforcursor "A",14,10000

'fwaitforappavailable ("A")

fwaitforinputready ("A")
fsendkeys "1"
fwaitforinputready ("A")
fsendkeys "[enter]"

'fwaitforattrib "A",6,"10","3c",3,10000

'fwaitforcursor "A",7,10000

'fwaitforappavailable ("A")

fwaitforinputready ("A")
fsendkeys "46,9"
fwaitforinputready ("A")
fsendkeys "[enter]"

'fwaitforattrib "A",39,"10","3c",3,10000

'fwaitforcursor "A",40,10000

'fwaitforappavailable ("A")

fwaitforinputready ("A")
fsendkeys "0283800"
fwaitforinputready ("A")
fsendkeys "[tab]"
fwaitforinputready ("A")
fsendkeys "1"
fwaitforinputready ("A")
fsendkeys "[tab]"
fwaitforinputready ("A")
fsendkeys "n"
fwaitforinputready ("A")
fsendkeys "[tab]"
fwaitforinputready ("A")
fsendkeys "001101"
fwaitforinputready ("A")
fsendkeys "[enter]"
end sub
From: mr_unreliable on
Doug Howell wrote:
> I guess I need to some how have the script determine what the session
> letter is for the one it just opened

hi Doug,

There is no doubt that you know a whole lot more about
the AS/400 terminal simulator than I do, but here is a
suggestion anyway.

As a "brute force" approach, you could get a list (a.k.a.
a "collection") of the terminal sessions in effect both
before and after you start your session. If you compare
the before and after listings, then (if all goes well)
you will find one more entry in the "after" collection
than in the "before" collection. That added entry will
be your session.

As to how to get the session collection, I was reading
here:

http://publib.boulder.ibm.com/infocenter/pcomhelp/v5r9/index.jsp?topic=/com.ibm.pcomm.doc/books/html/host_access08.htm

and found a class named: "autECLConnList Class". That
class may have something you can use.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)