Hi Folks
I'm currently writing some code in VBA which will automate some data input into our IBM Emulator (AS/400) which runs on VBSCript.
I used to use appactivate and sendkeys but this was not reliable for multiple reasons.
I therefore done some reading on the coding which the emulators run in and created some custom functions to help me.
Here is my custom functions:
and the main code:
The code works great. The thing I need help with is this - I need to use [mark right] and [edit copy] which I thought I could have done through my custom function "fsendkeys" but after reading I found out that [mark right] and [edit copy] come under the autECLMacro class. I have tried to use this but its not working.
Does anyone have any ideas how to A) use the autECLMacro object, or B) a way round this? The code I have above works (using excels sendkeys function) but id rather solve this so that the code can run in the background (if I use ecels sendkeys with the emulator then I cant use the PC when its running).
Many Thanks in advance for reading
Jamie
I'm currently writing some code in VBA which will automate some data input into our IBM Emulator (AS/400) which runs on VBSCript.
I used to use appactivate and sendkeys but this was not reliable for multiple reasons.
I therefore done some reading on the coding which the emulators run in and created some custom functions to help me.
Here is my custom functions:
Code:
Function fwaitforappavailable(SessionID)
Dim autECLOIAObj As Object
Set autECLOIAObj = CreateObject("PCOMM.autECLOIA")
autECLOIAObj.SetConnectionByName (SessionID)
If (autECLOIAObj.waitforappavailable(10000)) Then
'MsgBox "Application is available"
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
and the main code:
Code:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub SC05_CSOL_Check()
For counter1 = 2 To 10
acolumn = "A" & counter1
bcolumn = "B" & counter1
hno = Sheet1. Range(acolumn).Value
bcolumn = Sheet1.Range(bcolumn).Cells.Address
''''normally AppActivate "Session A - n3270"'''''''''''''
Dim SessObj As Object
Set SessObj = CreateObject("PCOMM.autECLSession")
' Initialize the session
SessObj.SetConnectionByName ("A")
''''''''''''''''''''''''''''''''''''''''''''''''''
fwaitforappavailable ("A")
fwaitforinputready ("A")
fsendkeys "[clear]"
fwaitforappavailable ("A")
fwaitforinputready ("A")
fsendkeys "SC05"
fwaitforinputready ("A")
fsendkeys "[enter]"
fwaitforattrib "A", 1, 7, "00", "3c", 3
fwaitforcursor "A", 1, 8
fwaitforappavailable ("A")
fwaitforinputready ("A")
fsendkeys hno
fwaitforinputready ("A")
fsendkeys "dis"
fwaitforinputready ("A")
fsendkeys "[enter]"
fwaitforattrib "A", 1, 2, "30", "3c", 3
fwaitforcursor "A", 1, 2
fwaitforappavailable ("A")
fwaitforinputready ("A")
fsetcursorpos 2, 54
fwaitforinputready ("A")
'need to [mark right] x 3 then [edit copy] here. fsendkeys does not work
AppActivate "Session A - tn3270"
sendkeys "```", True
Sleep 500
sendkeys "^c", True
AppActivate "Microsoft Excel"
Sheet1.Range(bcolumn).Select
sendkeys "^v", True
Next counter1
End Sub
The code works great. The thing I need help with is this - I need to use [mark right] and [edit copy] which I thought I could have done through my custom function "fsendkeys" but after reading I found out that [mark right] and [edit copy] come under the autECLMacro class. I have tried to use this but its not working.
Does anyone have any ideas how to A) use the autECLMacro object, or B) a way round this? The code I have above works (using excels sendkeys function) but id rather solve this so that the code can run in the background (if I use ecels sendkeys with the emulator then I cant use the PC when its running).
Many Thanks in advance for reading
Jamie