How to unlock X SYSTEM PCOMM ibm as400 terminal from within VBA excel code? If not autECLOIA.InputInhibited = 0 Then [duplicate]How to make SendKeys act Synchronously in IBM Host Access LibrarySending formatted Lotus Notes rich text email from Excel VBAHow to return a result from a VBA functionHow to avoid using Select in Excel VBAHow to add excel range as a picture to outlook message bodyOutlook 2010 VBA Task with attachmentsExcel Find a sheet based on nameExcel VBA URLDownloadToFile Error for HTTPSresourceShow only selected table column after filter to new worksheetsAS400 automate with VBA excelAutomate the pcomm login from Excel vba
Are there any of the Children of the Forest left, or are they extinct?
SafeCracker #3 - We've Been Blocked
Why are UK Bank Holidays on Mondays?
Decoupling cap routing on a 4 layer PCB
How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?
Copy previous line to current line from text file
Should I dumb down my writing in a foreign country?
What are the differences between credential stuffing and password spraying?
Can a Tiefling have more than two horns?
How to increase the size of the cursor in Lubuntu 19.04?
What does "Managed by Windows" do in the Power options for network connection?
Understanding trademark infringements in a world where many dictionary words are trademarks?
How can I get people to remember my character's gender?
Why aren't nationalizations in Russia described as socialist?
Should I decline this job offer that requires relocating to an area with high cost of living?
Can my company stop me from working overtime?
ZSPL language, anyone heard of it?
Pressure inside an infinite ocean?
How to write a 12-bar blues melody
What was Bran's plan to kill the Night King?
Where in Bitcoin Core does it do X?
Why wasn't the Night King naked in S08E03?
Can my 2 children 10 and 12 Travel to the USA on expired American Passports? They are US citizens
How should I tell my manager I'm not paying for an optional after work event I'm not going to?
How to unlock X SYSTEM PCOMM ibm as400 terminal from within VBA excel code? If not autECLOIA.InputInhibited = 0 Then [duplicate]
How to make SendKeys act Synchronously in IBM Host Access LibrarySending formatted Lotus Notes rich text email from Excel VBAHow to return a result from a VBA functionHow to avoid using Select in Excel VBAHow to add excel range as a picture to outlook message bodyOutlook 2010 VBA Task with attachmentsExcel Find a sheet based on nameExcel VBA URLDownloadToFile Error for HTTPSresourceShow only selected table column after filter to new worksheetsAS400 automate with VBA excelAutomate the pcomm login from Excel vba
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
How to make SendKeys act Synchronously in IBM Host Access Library
1 answer
I'm running an excel automation macro to read IbM as400 terminal window data. My macro is running faster than the terminal window causing sometimes the autECLOIA console msg system to stop with a red X SYSTEM stop message.
I tried to include in my code the
If not autECLOIA.InputInhibited = 0 Then
statement, but failed with error msg's.
Could someone help me?
Option Explicit
'
'<------------- Definitions --------------------------------------------------------------------
'
'main sheet and connectivity declarations
Public DAT As Worksheet
Public CurrentRow As Long
Public autECLSession As Object
Public autECLPS As Object
Public autECLOIA As Object
Public autECLConnList As Object
'main declarations used by forms
Public CompanyID As String
Public Cancel As Boolean
Public Curr As String
Public Route1 As String, Route2 As String
'date variable definitions for entire programm
Public TodaysDate As Date
Public TodaysDateShort As String
Public TodaysDateAS As String
Public TodaysDateQuery As String
Public StartDate As Date
Public EndDate As Date
Public EndDateShort As String
Public EndDateAS As String
Public EndDateQuery As String
Public dateVariable As Date
Public TimeNow As String
Public CurrentDate As Date
Public DateTime As String
Public DateQ As String
'other declarations - minor
Public From As String
Public StartRowST As Byte
Public CountDep As Byte
Public EndRowST As Byte
Public myNewRangeSize As String
'
'<------------- Main subroutine ----------------------------------------------------------------
'
Sub Start()
'definitions and for initialisation
Set DAT = Worksheets("DATA")
Load StartImport
StartImport.Show
If Cancel = True Then Exit Sub
'Accordingly to currency the route changes
If Curr = "PLN" Then
Route1 = "SWITRE"
Route2 = "TRESWI"
Else
Route1 = "KONTRE"
Route2 = "TREKON"
End If
'data transfer functions
'set and format dates
StartEndFormatDates
'start import
If CompanyID = "TT" Then
'code for importing TT-Line data kontinent to trelleborg
CurrentDate = StartDate
Do Until DateValue(CurrentDate) = DateValue(DateAdd("d", 1, EndDate))
EnterSailingTimetableCountOneDaysDepartures Route1, CurrentDate
'MsgBox "CurrentDate = " & CurrentDate & _
'vbCrLf & "StartRowST = " & StartRowST & _
'vbCrLf & "CountDep = " & CountDep & _
'vbCrLf & "EndRowST = " & EndRowST
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route1, CurrentDate
End If
'switching route
EnterSailingTimetableCountOneDaysDepartures Route2, CurrentDate
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route2, CurrentDate
End If
CurrentDate = DateAdd("d", 1, CurrentDate)
Loop
Else
'enter here code for importing other data
End If
Dim myNewRangeSize As Long
myNewRangeSize = DAT.Range("A1000000").End(xlUp).Row
DAT.ListObjects("DataTable").Resize Range("$A$1:$Z$" & myNewRangeSize)
End Sub
'
'<------------- Main functions -----------------------------------------------------------------
'
'formats start and end dates to 3 formats = Human, AS400 and Query
Function StartEndFormatDates()
'Work on todays date
TodaysDate = Format(Now, "dd.mm.yyyy")
TodaysDateShort = Format(TodaysDate, "dd.mm.yy")
TodaysDateAS = Format(TodaysDate, "ddmmyy")
Dim DateSplit() As String
DateSplit() = Split(TodaysDate, ".")
TodaysDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'Go to calendar to pick a date for outbound
'AdvancedCalendar 'checked
'Check if any date chosen from calendar
If EndDate < TodaysDate Then 'if user closes calendar without picking a date the program ends here
'SendKeys2Extra "[pf3]"
MsgBox ("You ended. Thank you.")
Call ObjEndExtra
Exit Function
End If
'EndDate = Format(dateVariable, "dd.mm.yyyy")
EndDateShort = Format(EndDate, "dd.mm.yy")
EndDateAS = Format(EndDate, "ddmmyy")
DateSplit() = Split(EndDate, ".")
EndDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'DispMsg (EndDate)
'time now
TimeNow = Format(Now, "hh:mm")
End Function
'enters ST in book window on given route and date --> counts first ST row and the number of departures
Function EnterSailingTimetableCountOneDaysDepartures(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ here I would want something like this @@@@@@@@@@@@@@@@@@@@@@@@@:
'If not autECLOIA.InputInhibited = 0 Then
' send "reset/ctrl"
'end if
'<=================================== but it doesn't work - generating object errors
'define variables
StartRowST = 0
CountDep = 0
EndRowST = 0
DateTime = ""
Dim i As Byte, stopif As Boolean
stopif = False
'start loop through ST screen to compare dates and time
For i = 1 To 18
autECLSession.autECLOIA.WaitForInputReady
'
'
FromAS 5 + i, 17, 8
'MsgBox "In search for last row:" & _
'vbCrLf & "From = " & CDate(Format(From, "dd.mm.yyyy")) & _
'vbCrLf & "Checkdate+1 day = " & CDate(DateAdd("d", 1, CheckDate))
Dim Spl() As String
Spl() = Split(From, ".")
From = Spl(0) & "." & Spl(1) & ".20" & Spl(2)
If CDate(From) = CDate(DateAdd("d", 1, CheckDate)) Then
'counts where is last Row in ST
If EndRowST > 0 Then
EndRowST = EndRowST - 1
Exit For
Else
Exit For
End If
Else
'read and set DateTime for determininig first row in ST
'FromAS 5 + i, 17, 8
DateTime = Format(From, "dd.mm.yyyy")
FromAS 5 + i, 32, 5
DateTime = DateTime & " " & Replace(From, ".", ":")
'MsgBox "DateTime = " & DateTime & _
'vbCrLf & "CheckDate = " & CheckDate & _
'vbCrLf & "Todaysdate+TimeNow = " & TodaysDate & " " & TimeNow
'check if DateTime read from ST bigger then Now - if so then counting first row and departures
If (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
StartRowST = 5 + i
CountDep = CountDep + 1
EndRowST = StartRowST
ElseIf (CDate(DateTime) < CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
stopif = True
ElseIf (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST > 0 Then
CountDep = CountDep + 1
End If
If stopif = False Then
EndRowST = EndRowST + 1
End If
End If
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
Function ImportMainST(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'
Dim i As Byte, j As Integer, x As Integer, y As Byte, startI As Integer
Dim Dep As String, Arr As String, WeekD As String, DepTime As String, Ship As String, _
WL As String, Canc As String, Price As String, BookedPax As String, Deck As String, _
FreePAX As String, FreeLPpax As String, MIS1 As Integer, MIS10 As Integer, _
MIS20 As Integer, MIS30 As Integer ', BPax As Integer
Dim Typ(19) As String
Dim BNAmo(19) As String 'booked normal cabins - type and amount
Dim KLAmo(19) As String 'booked komf/lux cabins sum
Dim FNAmo(19) As String 'free normal cabins sum
Dim FKLAmo(19) As String 'free komf/lux cabins sum
Dim FLPAmo(19) As String 'free low price cabins sum
Dim BNSum As Integer 'booked normal cabins sum
Dim KLSum As Integer 'booked komf/lux cabins sum
Dim FNSum As Integer 'free normal cabins sum
Dim FKLSum As Integer 'free komf/lux cabins sum
Dim FLPSum As Integer 'free low price cabins sum
startI = 1
'importing main ST screen
For i = StartRowST To EndRowST
CurrentRow = DAT.Cells(Rows.count, 1).End(xlUp).Row + 1
'<-------- Sail.Time: X -------->
If startI = 1 Then
'do nothing
Else
SendStr "X", 25, 31
Send "enter"
'
'
End If
'A date of entry - todaysdate
DAT.Range("A" & CurrentRow) = TodaysDate
'B compnay - CompanyComboBox
DAT.Range("B" & CurrentRow) = CompanyID
'C Dep
FromAS i, 6, 9
Dep = Left(From, 3)
DAT.Range("C" & CurrentRow) = Dep
'D Arr
Arr = Right(From, 3)
DAT.Range("D" & CurrentRow) = Arr
'E Dep date - CurrentDate
DAT.Range("E" & CurrentRow) = CurrentDate
'F Weekday
'FromAS i, 27, 2
'WeekD = From
DAT.Range("F" & CurrentRow) = Weekday(CurrentDate)
'G Time
FromAS i, 32, 5
DepTime = Replace(From, ".", ":")
DAT.Range("G" & CurrentRow) = DepTime
'Z Dep timeframe
If DepTime >= TimeValue("05:00:00") And DepTime < TimeValue("13:00:00") Then
DAT.Range("Z" & CurrentRow) = "Morning"
ElseIf DepTime >= TimeValue("13:00:00") And DepTime < TimeValue("19:00:00") Then
DAT.Range("Z" & CurrentRow) = "Afternoon"
ElseIf DepTime >= TimeValue("19:00:00") And DepTime < TimeValue("00:00:00") Then
DAT.Range("Z" & CurrentRow) = "Evening"
ElseIf DepTime >= TimeValue("00:00:00") And DepTime < TimeValue("05:00:00") Then
DAT.Range("Z" & CurrentRow) = "Night"
End If
'H Ship
FromAS i, 39, 2
Ship = From
DAT.Range("H" & CurrentRow) = Ship
'I WL
FromAS i, 59, 3
If Trim(From) <> "" Then WL = From
DAT.Range("I" & CurrentRow) = WL
'J Canc
FromAS i, 72, 4
If Trim(From) <> "" Then Canc = From
DAT.Range("J" & CurrentRow) = From
If DAT.Range("J" & CurrentRow) <> "CANC" Then
'K - Price
FromAS i, 85, 4
Price = Trim(From)
DAT.Range("K" & CurrentRow) = Price
'L - Currency from CurrencyComboBox
DAT.Range("L" & CurrentRow) = Curr
'<-------- Cabin-Av: B -------->
SendStr "B", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'M booked PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
BookedPax = Trim(From)
Else
BookedPax = 0
End If
DAT.Range("M" & CurrentRow) = BookedPax
'T - Booked Cab
BNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
BNAmo(j) = Trim(From)
If IsNumeric(Trim(BNAmo(j))) = True Then
'MsgBox "Right(Trim(Typ(j)), 1) = " & Right(Trim(Typ(j)), 1) & vbCrLf & "Trim(Typ(j) = " & Trim(Typ(j))
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
BNSum = BNSum + CInt(BNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & BNAmo(j)
Next j
DAT.Range("T" & CurrentRow) = BNSum
'U - Booked K/L Cab
KLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
KLAmo(j) = Trim(From)
If IsNumeric(Trim(KLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
KLSum = KLSum + CInt(KLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & KLAmo(j)
Next j
DAT.Range("U" & CurrentRow) = KLSum
'<-------- Cabin-Av: X -------->
SendStr "X", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'R free PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreePAX = Trim(From)
Else
FreePAX = 0
End If
DAT.Range("R" & CurrentRow) = FreePAX
'V - Free Cabins
FNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FNAmo(j) = Trim(From)
If IsNumeric(Trim(FNAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L" Or Trim(Typ(j)) <> "SU4") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
FNSum = FNSum + CInt(FNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FNAmo(j)
Next j
DAT.Range("V" & CurrentRow) = FNSum
'W - Free K/L Cab
FKLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
FKLAmo(j) = Trim(From)
If IsNumeric(Trim(FKLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L" Or Trim(Typ(j)) = "SU4") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
FKLSum = FKLSum + CInt(FKLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FKLAmo(j)
Next j
DAT.Range("W" & CurrentRow) = FKLSum
'<-------- Cabin-Av: L -------->
SendStr "L", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'S - Free LP PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreeLPpax = Trim(From)
Else
FreeLPpax = 0
End If
DAT.Range("S" & CurrentRow) = FreeLPpax
'X - Free LP Cab
FLPSum = 0
x = 0
For j = 0 To 19
FromAS 4, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FLPAmo(j) = Trim(From)
If IsNumeric(Trim(FLPAmo(j))) = True Then
If Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL" Then
FLPSum = FLPSum + CInt(FLPAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FLPAmo(j)
Next j
DAT.Range("X" & CurrentRow) = FLPSum
'<--------Deck-Av: X -------->
SendStr "X", 25, 54
Send "Enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Y Free Deck
FromAS i, 32, 3
Deck = Trim(From)
DAT.Range("Y" & CurrentRow) = Deck
'<-------- Query -------->
Send "pf3"
Send "pf3"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "6", 20, 7
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "2", 5, 26
SendStr "KOORDINAT", 9, 28
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Send "pf4"
SendStr "2A_01GREG", 11, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 13, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Dim SplQ() As String
SplQ() = Split(CheckDate, ".")
DateQ = SplQ(2) & "-" & SplQ(1) & "-" & SplQ(0)
SendStr DateQ, 7, 36
SendStr Dep, 8, 36
SendStr Arr, 9, 36
SendStr DepTime, 10, 36
'
'
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLOIA.WaitForInputReady
SendStr "'01' ", 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'N Booked MIS 1
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS1 = Trim(From)
Else
MIS1 = 0
End If
Else
MIS1 = 0
End If
DAT.Range("N" & CurrentRow) = MIS1
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'10' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'O MIS 10
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS10 = Trim(From)
Else
MIS10 = 0
End If
Else
MIS10 = 0
End If
DAT.Range("O" & CurrentRow) = MIS10
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'20' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'P MIS 20
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS20 = Trim(From)
Else
MIS20 = 0
End If
Else
MIS20 = 0
End If
DAT.Range("P" & CurrentRow) = MIS20
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'30' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Q MIS 30
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS30 = Trim(From)
Else
MIS30 = 0
End If
Else
MIS30 = 0
End If
DAT.Range("Q" & CurrentRow) = MIS30
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf12"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady (750)
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "N", 5, 29
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "13", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
CheckResource
If CheckResource = True Then
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
Else
MsgBox "Error. Not in ST. Unlock book window, and go to ST. If macro starts, leave it.", vbOKOnly, "Error"
End If
End If
'
'
startI = startI + 1
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
'<------------------------------- START, STOP FUNCTIONS -------------------------------------
'
' Set up fields need to link to 5250 session - Copy this block into any new Screen Scrapper macro as is
'
Sub ObjGetExtra()
DAT.Unprotect ("Coordination")
'DAT.Select
Set autECLSession = CreateObject("pcomm.auteclsession")
Set autECLPS = CreateObject("PCOMM.autECLPS")
Set autECLOIA = CreateObject("Pcomm.autecloia")
'Set autECLConnList = CreateObject("PCOMM.autECLConnList")
End Sub
Sub ObjEndExtra()
Set autECLSession = Nothing
Set autECLPS = Nothing
Set autECLOIA = Nothing
'Set autECLConnList = Nothing
DAT.Protect ("Coordination")
End Sub
'<------------------------------ FUNCTIONS FOR AS400 PROCESSING --------------------------------
'
' Put the value on the 5250 screen at the position specified
'
Function SendStr(ByVal Data As String, ByVal Row As Long, ByVal Col As Long)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos Row, Col
autECLSession.autECLPS.SendKeys Data, Row, Col
End Function
'
' Read a string from the 5250 screen strarting at the position specified
'
Function FromAS(ByVal Row As Long, ByVal Col As Long, ByVal Lenght As Long) As String
autECLSession.autECLOIA.WaitForInputReady
From = autECLSession.autECLPS.GetText(Row, Col, Lenght)
End Function
'
' Sent special keys to the session (function keys, enter, etc)
'
Function Send(Key As String)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[" & Key & "]"
End Function
' Check if in Sailing Timetable
Function CheckResource() As Boolean
FromAS 2, 20, 7
'
'
If Trim(From) = "SAILING" Then
FromAS 4, 11, 5
'
'
'
If Trim(From) = "Route" Then
'do nothing
CheckResource = True
Else
FromAS 4, 2, 3
'
'
If Trim(From) = "Seq" Then
Send "pf3"
CheckResource = True
End If
End If
Else
CheckResource = False
End If
End Function
'the form starting the comm session is here
'StartImport form code
'
Public SessionString As String
'Public handleConn As Byte
Private Sub RunButton_Click()
If CompanyComboBox <> "select" Then
If CompanyComboBox = "TT" And CurrencyComboBox <> "select" Then
If SessionString <> "" Then
'proper start sequence
Call ObjGetExtra
autECLSession.SetConnectionByname (SessionString)
autECLPS.SetConnectionByname (SessionString)
'autECLConnList.Refresh
autECLOIA.SetConnectionByname (SessionString)
If autECLSession.commstarted = False Then
MsgBox "There does not appear to be a session '" & SessionString & "'. Please Check and try again.", vbOKOnly, "Error"
Call ObjEndExtra
End If
Call CheckResource
If CheckResource = True Then
CompanyID = CompanyComboBox
Curr = CurrencyComboBox
StartDate = FromDateF
EndDate = ToDateF
Unload Me
Else
MsgBox "You are not in ST, please start ST in choosen session and start again.", vbOKOnly, "Error"
End If
Else
MsgBox "No Session button choosen.", vbOKOnly, "Error"
End If
ElseIf CompanyComboBox <> "TT" Then
CompanyID = CompanyComboBox
CurrencyComboBox = "EUR"
StartDate = FromDateF
EndDate = ToDateF
Unload Me
End If
Else
MsgBox "Nothing selected to be done", vbOKOnly, "Error"
End If
End Sub
Private Sub Session1_Click()
If Session1 = True Then
SessionString = "A"
'handleConn = 1
Session2 = False
Session3 = False
End If
End Sub
Private Sub Session2_Click()
If Session2 = True Then
SessionString = "B"
'handleConn = 2
Session1 = False
Session3 = False
End If
End Sub
Private Sub Session3_Click()
If Session3 = True Then
SessionString = "C"
'handleConn = 3
Session1 = False
Session2 = False
End If
End Sub
Private Sub CompanyComboBox_Change()
If CompanyComboBox = "TT" Then CurrencyComboBox.value = "select"
End Sub
Private Sub CancelButton_Click()
UserForm_QueryClose 0, 0
End Sub
Private Sub UserForm_Initialize()
'Company choice
With Me.CompanyComboBox
.AddItem "TT"
'rest deleted
End With
'Currency choice
With Me.CurrencyComboBox
.AddItem "EUR"
'rest deleted
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Call ObjEndExtra
Cancel = True
Unload Me
MsgBox "You ended. Thank you.", vbOKOnly, "Exit"
End
End If
End Sub
everywhere where you see in two lines: '
there should be some error handling like (above from code):
If not autECLOIA.InputInhibited = 0 Then
send "reset/ctrl"
end if
but it doesn't work - generating object errors
excel vba automation screen-scraping ibm-midrange
marked as duplicate by Charles, Community♦ Mar 26 at 16:44
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to make SendKeys act Synchronously in IBM Host Access Library
1 answer
I'm running an excel automation macro to read IbM as400 terminal window data. My macro is running faster than the terminal window causing sometimes the autECLOIA console msg system to stop with a red X SYSTEM stop message.
I tried to include in my code the
If not autECLOIA.InputInhibited = 0 Then
statement, but failed with error msg's.
Could someone help me?
Option Explicit
'
'<------------- Definitions --------------------------------------------------------------------
'
'main sheet and connectivity declarations
Public DAT As Worksheet
Public CurrentRow As Long
Public autECLSession As Object
Public autECLPS As Object
Public autECLOIA As Object
Public autECLConnList As Object
'main declarations used by forms
Public CompanyID As String
Public Cancel As Boolean
Public Curr As String
Public Route1 As String, Route2 As String
'date variable definitions for entire programm
Public TodaysDate As Date
Public TodaysDateShort As String
Public TodaysDateAS As String
Public TodaysDateQuery As String
Public StartDate As Date
Public EndDate As Date
Public EndDateShort As String
Public EndDateAS As String
Public EndDateQuery As String
Public dateVariable As Date
Public TimeNow As String
Public CurrentDate As Date
Public DateTime As String
Public DateQ As String
'other declarations - minor
Public From As String
Public StartRowST As Byte
Public CountDep As Byte
Public EndRowST As Byte
Public myNewRangeSize As String
'
'<------------- Main subroutine ----------------------------------------------------------------
'
Sub Start()
'definitions and for initialisation
Set DAT = Worksheets("DATA")
Load StartImport
StartImport.Show
If Cancel = True Then Exit Sub
'Accordingly to currency the route changes
If Curr = "PLN" Then
Route1 = "SWITRE"
Route2 = "TRESWI"
Else
Route1 = "KONTRE"
Route2 = "TREKON"
End If
'data transfer functions
'set and format dates
StartEndFormatDates
'start import
If CompanyID = "TT" Then
'code for importing TT-Line data kontinent to trelleborg
CurrentDate = StartDate
Do Until DateValue(CurrentDate) = DateValue(DateAdd("d", 1, EndDate))
EnterSailingTimetableCountOneDaysDepartures Route1, CurrentDate
'MsgBox "CurrentDate = " & CurrentDate & _
'vbCrLf & "StartRowST = " & StartRowST & _
'vbCrLf & "CountDep = " & CountDep & _
'vbCrLf & "EndRowST = " & EndRowST
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route1, CurrentDate
End If
'switching route
EnterSailingTimetableCountOneDaysDepartures Route2, CurrentDate
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route2, CurrentDate
End If
CurrentDate = DateAdd("d", 1, CurrentDate)
Loop
Else
'enter here code for importing other data
End If
Dim myNewRangeSize As Long
myNewRangeSize = DAT.Range("A1000000").End(xlUp).Row
DAT.ListObjects("DataTable").Resize Range("$A$1:$Z$" & myNewRangeSize)
End Sub
'
'<------------- Main functions -----------------------------------------------------------------
'
'formats start and end dates to 3 formats = Human, AS400 and Query
Function StartEndFormatDates()
'Work on todays date
TodaysDate = Format(Now, "dd.mm.yyyy")
TodaysDateShort = Format(TodaysDate, "dd.mm.yy")
TodaysDateAS = Format(TodaysDate, "ddmmyy")
Dim DateSplit() As String
DateSplit() = Split(TodaysDate, ".")
TodaysDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'Go to calendar to pick a date for outbound
'AdvancedCalendar 'checked
'Check if any date chosen from calendar
If EndDate < TodaysDate Then 'if user closes calendar without picking a date the program ends here
'SendKeys2Extra "[pf3]"
MsgBox ("You ended. Thank you.")
Call ObjEndExtra
Exit Function
End If
'EndDate = Format(dateVariable, "dd.mm.yyyy")
EndDateShort = Format(EndDate, "dd.mm.yy")
EndDateAS = Format(EndDate, "ddmmyy")
DateSplit() = Split(EndDate, ".")
EndDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'DispMsg (EndDate)
'time now
TimeNow = Format(Now, "hh:mm")
End Function
'enters ST in book window on given route and date --> counts first ST row and the number of departures
Function EnterSailingTimetableCountOneDaysDepartures(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ here I would want something like this @@@@@@@@@@@@@@@@@@@@@@@@@:
'If not autECLOIA.InputInhibited = 0 Then
' send "reset/ctrl"
'end if
'<=================================== but it doesn't work - generating object errors
'define variables
StartRowST = 0
CountDep = 0
EndRowST = 0
DateTime = ""
Dim i As Byte, stopif As Boolean
stopif = False
'start loop through ST screen to compare dates and time
For i = 1 To 18
autECLSession.autECLOIA.WaitForInputReady
'
'
FromAS 5 + i, 17, 8
'MsgBox "In search for last row:" & _
'vbCrLf & "From = " & CDate(Format(From, "dd.mm.yyyy")) & _
'vbCrLf & "Checkdate+1 day = " & CDate(DateAdd("d", 1, CheckDate))
Dim Spl() As String
Spl() = Split(From, ".")
From = Spl(0) & "." & Spl(1) & ".20" & Spl(2)
If CDate(From) = CDate(DateAdd("d", 1, CheckDate)) Then
'counts where is last Row in ST
If EndRowST > 0 Then
EndRowST = EndRowST - 1
Exit For
Else
Exit For
End If
Else
'read and set DateTime for determininig first row in ST
'FromAS 5 + i, 17, 8
DateTime = Format(From, "dd.mm.yyyy")
FromAS 5 + i, 32, 5
DateTime = DateTime & " " & Replace(From, ".", ":")
'MsgBox "DateTime = " & DateTime & _
'vbCrLf & "CheckDate = " & CheckDate & _
'vbCrLf & "Todaysdate+TimeNow = " & TodaysDate & " " & TimeNow
'check if DateTime read from ST bigger then Now - if so then counting first row and departures
If (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
StartRowST = 5 + i
CountDep = CountDep + 1
EndRowST = StartRowST
ElseIf (CDate(DateTime) < CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
stopif = True
ElseIf (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST > 0 Then
CountDep = CountDep + 1
End If
If stopif = False Then
EndRowST = EndRowST + 1
End If
End If
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
Function ImportMainST(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'
Dim i As Byte, j As Integer, x As Integer, y As Byte, startI As Integer
Dim Dep As String, Arr As String, WeekD As String, DepTime As String, Ship As String, _
WL As String, Canc As String, Price As String, BookedPax As String, Deck As String, _
FreePAX As String, FreeLPpax As String, MIS1 As Integer, MIS10 As Integer, _
MIS20 As Integer, MIS30 As Integer ', BPax As Integer
Dim Typ(19) As String
Dim BNAmo(19) As String 'booked normal cabins - type and amount
Dim KLAmo(19) As String 'booked komf/lux cabins sum
Dim FNAmo(19) As String 'free normal cabins sum
Dim FKLAmo(19) As String 'free komf/lux cabins sum
Dim FLPAmo(19) As String 'free low price cabins sum
Dim BNSum As Integer 'booked normal cabins sum
Dim KLSum As Integer 'booked komf/lux cabins sum
Dim FNSum As Integer 'free normal cabins sum
Dim FKLSum As Integer 'free komf/lux cabins sum
Dim FLPSum As Integer 'free low price cabins sum
startI = 1
'importing main ST screen
For i = StartRowST To EndRowST
CurrentRow = DAT.Cells(Rows.count, 1).End(xlUp).Row + 1
'<-------- Sail.Time: X -------->
If startI = 1 Then
'do nothing
Else
SendStr "X", 25, 31
Send "enter"
'
'
End If
'A date of entry - todaysdate
DAT.Range("A" & CurrentRow) = TodaysDate
'B compnay - CompanyComboBox
DAT.Range("B" & CurrentRow) = CompanyID
'C Dep
FromAS i, 6, 9
Dep = Left(From, 3)
DAT.Range("C" & CurrentRow) = Dep
'D Arr
Arr = Right(From, 3)
DAT.Range("D" & CurrentRow) = Arr
'E Dep date - CurrentDate
DAT.Range("E" & CurrentRow) = CurrentDate
'F Weekday
'FromAS i, 27, 2
'WeekD = From
DAT.Range("F" & CurrentRow) = Weekday(CurrentDate)
'G Time
FromAS i, 32, 5
DepTime = Replace(From, ".", ":")
DAT.Range("G" & CurrentRow) = DepTime
'Z Dep timeframe
If DepTime >= TimeValue("05:00:00") And DepTime < TimeValue("13:00:00") Then
DAT.Range("Z" & CurrentRow) = "Morning"
ElseIf DepTime >= TimeValue("13:00:00") And DepTime < TimeValue("19:00:00") Then
DAT.Range("Z" & CurrentRow) = "Afternoon"
ElseIf DepTime >= TimeValue("19:00:00") And DepTime < TimeValue("00:00:00") Then
DAT.Range("Z" & CurrentRow) = "Evening"
ElseIf DepTime >= TimeValue("00:00:00") And DepTime < TimeValue("05:00:00") Then
DAT.Range("Z" & CurrentRow) = "Night"
End If
'H Ship
FromAS i, 39, 2
Ship = From
DAT.Range("H" & CurrentRow) = Ship
'I WL
FromAS i, 59, 3
If Trim(From) <> "" Then WL = From
DAT.Range("I" & CurrentRow) = WL
'J Canc
FromAS i, 72, 4
If Trim(From) <> "" Then Canc = From
DAT.Range("J" & CurrentRow) = From
If DAT.Range("J" & CurrentRow) <> "CANC" Then
'K - Price
FromAS i, 85, 4
Price = Trim(From)
DAT.Range("K" & CurrentRow) = Price
'L - Currency from CurrencyComboBox
DAT.Range("L" & CurrentRow) = Curr
'<-------- Cabin-Av: B -------->
SendStr "B", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'M booked PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
BookedPax = Trim(From)
Else
BookedPax = 0
End If
DAT.Range("M" & CurrentRow) = BookedPax
'T - Booked Cab
BNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
BNAmo(j) = Trim(From)
If IsNumeric(Trim(BNAmo(j))) = True Then
'MsgBox "Right(Trim(Typ(j)), 1) = " & Right(Trim(Typ(j)), 1) & vbCrLf & "Trim(Typ(j) = " & Trim(Typ(j))
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
BNSum = BNSum + CInt(BNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & BNAmo(j)
Next j
DAT.Range("T" & CurrentRow) = BNSum
'U - Booked K/L Cab
KLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
KLAmo(j) = Trim(From)
If IsNumeric(Trim(KLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
KLSum = KLSum + CInt(KLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & KLAmo(j)
Next j
DAT.Range("U" & CurrentRow) = KLSum
'<-------- Cabin-Av: X -------->
SendStr "X", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'R free PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreePAX = Trim(From)
Else
FreePAX = 0
End If
DAT.Range("R" & CurrentRow) = FreePAX
'V - Free Cabins
FNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FNAmo(j) = Trim(From)
If IsNumeric(Trim(FNAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L" Or Trim(Typ(j)) <> "SU4") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
FNSum = FNSum + CInt(FNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FNAmo(j)
Next j
DAT.Range("V" & CurrentRow) = FNSum
'W - Free K/L Cab
FKLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
FKLAmo(j) = Trim(From)
If IsNumeric(Trim(FKLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L" Or Trim(Typ(j)) = "SU4") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
FKLSum = FKLSum + CInt(FKLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FKLAmo(j)
Next j
DAT.Range("W" & CurrentRow) = FKLSum
'<-------- Cabin-Av: L -------->
SendStr "L", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'S - Free LP PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreeLPpax = Trim(From)
Else
FreeLPpax = 0
End If
DAT.Range("S" & CurrentRow) = FreeLPpax
'X - Free LP Cab
FLPSum = 0
x = 0
For j = 0 To 19
FromAS 4, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FLPAmo(j) = Trim(From)
If IsNumeric(Trim(FLPAmo(j))) = True Then
If Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL" Then
FLPSum = FLPSum + CInt(FLPAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FLPAmo(j)
Next j
DAT.Range("X" & CurrentRow) = FLPSum
'<--------Deck-Av: X -------->
SendStr "X", 25, 54
Send "Enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Y Free Deck
FromAS i, 32, 3
Deck = Trim(From)
DAT.Range("Y" & CurrentRow) = Deck
'<-------- Query -------->
Send "pf3"
Send "pf3"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "6", 20, 7
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "2", 5, 26
SendStr "KOORDINAT", 9, 28
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Send "pf4"
SendStr "2A_01GREG", 11, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 13, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Dim SplQ() As String
SplQ() = Split(CheckDate, ".")
DateQ = SplQ(2) & "-" & SplQ(1) & "-" & SplQ(0)
SendStr DateQ, 7, 36
SendStr Dep, 8, 36
SendStr Arr, 9, 36
SendStr DepTime, 10, 36
'
'
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLOIA.WaitForInputReady
SendStr "'01' ", 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'N Booked MIS 1
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS1 = Trim(From)
Else
MIS1 = 0
End If
Else
MIS1 = 0
End If
DAT.Range("N" & CurrentRow) = MIS1
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'10' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'O MIS 10
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS10 = Trim(From)
Else
MIS10 = 0
End If
Else
MIS10 = 0
End If
DAT.Range("O" & CurrentRow) = MIS10
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'20' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'P MIS 20
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS20 = Trim(From)
Else
MIS20 = 0
End If
Else
MIS20 = 0
End If
DAT.Range("P" & CurrentRow) = MIS20
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'30' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Q MIS 30
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS30 = Trim(From)
Else
MIS30 = 0
End If
Else
MIS30 = 0
End If
DAT.Range("Q" & CurrentRow) = MIS30
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf12"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady (750)
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "N", 5, 29
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "13", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
CheckResource
If CheckResource = True Then
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
Else
MsgBox "Error. Not in ST. Unlock book window, and go to ST. If macro starts, leave it.", vbOKOnly, "Error"
End If
End If
'
'
startI = startI + 1
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
'<------------------------------- START, STOP FUNCTIONS -------------------------------------
'
' Set up fields need to link to 5250 session - Copy this block into any new Screen Scrapper macro as is
'
Sub ObjGetExtra()
DAT.Unprotect ("Coordination")
'DAT.Select
Set autECLSession = CreateObject("pcomm.auteclsession")
Set autECLPS = CreateObject("PCOMM.autECLPS")
Set autECLOIA = CreateObject("Pcomm.autecloia")
'Set autECLConnList = CreateObject("PCOMM.autECLConnList")
End Sub
Sub ObjEndExtra()
Set autECLSession = Nothing
Set autECLPS = Nothing
Set autECLOIA = Nothing
'Set autECLConnList = Nothing
DAT.Protect ("Coordination")
End Sub
'<------------------------------ FUNCTIONS FOR AS400 PROCESSING --------------------------------
'
' Put the value on the 5250 screen at the position specified
'
Function SendStr(ByVal Data As String, ByVal Row As Long, ByVal Col As Long)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos Row, Col
autECLSession.autECLPS.SendKeys Data, Row, Col
End Function
'
' Read a string from the 5250 screen strarting at the position specified
'
Function FromAS(ByVal Row As Long, ByVal Col As Long, ByVal Lenght As Long) As String
autECLSession.autECLOIA.WaitForInputReady
From = autECLSession.autECLPS.GetText(Row, Col, Lenght)
End Function
'
' Sent special keys to the session (function keys, enter, etc)
'
Function Send(Key As String)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[" & Key & "]"
End Function
' Check if in Sailing Timetable
Function CheckResource() As Boolean
FromAS 2, 20, 7
'
'
If Trim(From) = "SAILING" Then
FromAS 4, 11, 5
'
'
'
If Trim(From) = "Route" Then
'do nothing
CheckResource = True
Else
FromAS 4, 2, 3
'
'
If Trim(From) = "Seq" Then
Send "pf3"
CheckResource = True
End If
End If
Else
CheckResource = False
End If
End Function
'the form starting the comm session is here
'StartImport form code
'
Public SessionString As String
'Public handleConn As Byte
Private Sub RunButton_Click()
If CompanyComboBox <> "select" Then
If CompanyComboBox = "TT" And CurrencyComboBox <> "select" Then
If SessionString <> "" Then
'proper start sequence
Call ObjGetExtra
autECLSession.SetConnectionByname (SessionString)
autECLPS.SetConnectionByname (SessionString)
'autECLConnList.Refresh
autECLOIA.SetConnectionByname (SessionString)
If autECLSession.commstarted = False Then
MsgBox "There does not appear to be a session '" & SessionString & "'. Please Check and try again.", vbOKOnly, "Error"
Call ObjEndExtra
End If
Call CheckResource
If CheckResource = True Then
CompanyID = CompanyComboBox
Curr = CurrencyComboBox
StartDate = FromDateF
EndDate = ToDateF
Unload Me
Else
MsgBox "You are not in ST, please start ST in choosen session and start again.", vbOKOnly, "Error"
End If
Else
MsgBox "No Session button choosen.", vbOKOnly, "Error"
End If
ElseIf CompanyComboBox <> "TT" Then
CompanyID = CompanyComboBox
CurrencyComboBox = "EUR"
StartDate = FromDateF
EndDate = ToDateF
Unload Me
End If
Else
MsgBox "Nothing selected to be done", vbOKOnly, "Error"
End If
End Sub
Private Sub Session1_Click()
If Session1 = True Then
SessionString = "A"
'handleConn = 1
Session2 = False
Session3 = False
End If
End Sub
Private Sub Session2_Click()
If Session2 = True Then
SessionString = "B"
'handleConn = 2
Session1 = False
Session3 = False
End If
End Sub
Private Sub Session3_Click()
If Session3 = True Then
SessionString = "C"
'handleConn = 3
Session1 = False
Session2 = False
End If
End Sub
Private Sub CompanyComboBox_Change()
If CompanyComboBox = "TT" Then CurrencyComboBox.value = "select"
End Sub
Private Sub CancelButton_Click()
UserForm_QueryClose 0, 0
End Sub
Private Sub UserForm_Initialize()
'Company choice
With Me.CompanyComboBox
.AddItem "TT"
'rest deleted
End With
'Currency choice
With Me.CurrencyComboBox
.AddItem "EUR"
'rest deleted
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Call ObjEndExtra
Cancel = True
Unload Me
MsgBox "You ended. Thank you.", vbOKOnly, "Exit"
End
End If
End Sub
everywhere where you see in two lines: '
there should be some error handling like (above from code):
If not autECLOIA.InputInhibited = 0 Then
send "reset/ctrl"
end if
but it doesn't work - generating object errors
excel vba automation screen-scraping ibm-midrange
marked as duplicate by Charles, Community♦ Mar 26 at 16:44
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to make SendKeys act Synchronously in IBM Host Access Library
1 answer
I'm running an excel automation macro to read IbM as400 terminal window data. My macro is running faster than the terminal window causing sometimes the autECLOIA console msg system to stop with a red X SYSTEM stop message.
I tried to include in my code the
If not autECLOIA.InputInhibited = 0 Then
statement, but failed with error msg's.
Could someone help me?
Option Explicit
'
'<------------- Definitions --------------------------------------------------------------------
'
'main sheet and connectivity declarations
Public DAT As Worksheet
Public CurrentRow As Long
Public autECLSession As Object
Public autECLPS As Object
Public autECLOIA As Object
Public autECLConnList As Object
'main declarations used by forms
Public CompanyID As String
Public Cancel As Boolean
Public Curr As String
Public Route1 As String, Route2 As String
'date variable definitions for entire programm
Public TodaysDate As Date
Public TodaysDateShort As String
Public TodaysDateAS As String
Public TodaysDateQuery As String
Public StartDate As Date
Public EndDate As Date
Public EndDateShort As String
Public EndDateAS As String
Public EndDateQuery As String
Public dateVariable As Date
Public TimeNow As String
Public CurrentDate As Date
Public DateTime As String
Public DateQ As String
'other declarations - minor
Public From As String
Public StartRowST As Byte
Public CountDep As Byte
Public EndRowST As Byte
Public myNewRangeSize As String
'
'<------------- Main subroutine ----------------------------------------------------------------
'
Sub Start()
'definitions and for initialisation
Set DAT = Worksheets("DATA")
Load StartImport
StartImport.Show
If Cancel = True Then Exit Sub
'Accordingly to currency the route changes
If Curr = "PLN" Then
Route1 = "SWITRE"
Route2 = "TRESWI"
Else
Route1 = "KONTRE"
Route2 = "TREKON"
End If
'data transfer functions
'set and format dates
StartEndFormatDates
'start import
If CompanyID = "TT" Then
'code for importing TT-Line data kontinent to trelleborg
CurrentDate = StartDate
Do Until DateValue(CurrentDate) = DateValue(DateAdd("d", 1, EndDate))
EnterSailingTimetableCountOneDaysDepartures Route1, CurrentDate
'MsgBox "CurrentDate = " & CurrentDate & _
'vbCrLf & "StartRowST = " & StartRowST & _
'vbCrLf & "CountDep = " & CountDep & _
'vbCrLf & "EndRowST = " & EndRowST
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route1, CurrentDate
End If
'switching route
EnterSailingTimetableCountOneDaysDepartures Route2, CurrentDate
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route2, CurrentDate
End If
CurrentDate = DateAdd("d", 1, CurrentDate)
Loop
Else
'enter here code for importing other data
End If
Dim myNewRangeSize As Long
myNewRangeSize = DAT.Range("A1000000").End(xlUp).Row
DAT.ListObjects("DataTable").Resize Range("$A$1:$Z$" & myNewRangeSize)
End Sub
'
'<------------- Main functions -----------------------------------------------------------------
'
'formats start and end dates to 3 formats = Human, AS400 and Query
Function StartEndFormatDates()
'Work on todays date
TodaysDate = Format(Now, "dd.mm.yyyy")
TodaysDateShort = Format(TodaysDate, "dd.mm.yy")
TodaysDateAS = Format(TodaysDate, "ddmmyy")
Dim DateSplit() As String
DateSplit() = Split(TodaysDate, ".")
TodaysDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'Go to calendar to pick a date for outbound
'AdvancedCalendar 'checked
'Check if any date chosen from calendar
If EndDate < TodaysDate Then 'if user closes calendar without picking a date the program ends here
'SendKeys2Extra "[pf3]"
MsgBox ("You ended. Thank you.")
Call ObjEndExtra
Exit Function
End If
'EndDate = Format(dateVariable, "dd.mm.yyyy")
EndDateShort = Format(EndDate, "dd.mm.yy")
EndDateAS = Format(EndDate, "ddmmyy")
DateSplit() = Split(EndDate, ".")
EndDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'DispMsg (EndDate)
'time now
TimeNow = Format(Now, "hh:mm")
End Function
'enters ST in book window on given route and date --> counts first ST row and the number of departures
Function EnterSailingTimetableCountOneDaysDepartures(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ here I would want something like this @@@@@@@@@@@@@@@@@@@@@@@@@:
'If not autECLOIA.InputInhibited = 0 Then
' send "reset/ctrl"
'end if
'<=================================== but it doesn't work - generating object errors
'define variables
StartRowST = 0
CountDep = 0
EndRowST = 0
DateTime = ""
Dim i As Byte, stopif As Boolean
stopif = False
'start loop through ST screen to compare dates and time
For i = 1 To 18
autECLSession.autECLOIA.WaitForInputReady
'
'
FromAS 5 + i, 17, 8
'MsgBox "In search for last row:" & _
'vbCrLf & "From = " & CDate(Format(From, "dd.mm.yyyy")) & _
'vbCrLf & "Checkdate+1 day = " & CDate(DateAdd("d", 1, CheckDate))
Dim Spl() As String
Spl() = Split(From, ".")
From = Spl(0) & "." & Spl(1) & ".20" & Spl(2)
If CDate(From) = CDate(DateAdd("d", 1, CheckDate)) Then
'counts where is last Row in ST
If EndRowST > 0 Then
EndRowST = EndRowST - 1
Exit For
Else
Exit For
End If
Else
'read and set DateTime for determininig first row in ST
'FromAS 5 + i, 17, 8
DateTime = Format(From, "dd.mm.yyyy")
FromAS 5 + i, 32, 5
DateTime = DateTime & " " & Replace(From, ".", ":")
'MsgBox "DateTime = " & DateTime & _
'vbCrLf & "CheckDate = " & CheckDate & _
'vbCrLf & "Todaysdate+TimeNow = " & TodaysDate & " " & TimeNow
'check if DateTime read from ST bigger then Now - if so then counting first row and departures
If (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
StartRowST = 5 + i
CountDep = CountDep + 1
EndRowST = StartRowST
ElseIf (CDate(DateTime) < CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
stopif = True
ElseIf (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST > 0 Then
CountDep = CountDep + 1
End If
If stopif = False Then
EndRowST = EndRowST + 1
End If
End If
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
Function ImportMainST(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'
Dim i As Byte, j As Integer, x As Integer, y As Byte, startI As Integer
Dim Dep As String, Arr As String, WeekD As String, DepTime As String, Ship As String, _
WL As String, Canc As String, Price As String, BookedPax As String, Deck As String, _
FreePAX As String, FreeLPpax As String, MIS1 As Integer, MIS10 As Integer, _
MIS20 As Integer, MIS30 As Integer ', BPax As Integer
Dim Typ(19) As String
Dim BNAmo(19) As String 'booked normal cabins - type and amount
Dim KLAmo(19) As String 'booked komf/lux cabins sum
Dim FNAmo(19) As String 'free normal cabins sum
Dim FKLAmo(19) As String 'free komf/lux cabins sum
Dim FLPAmo(19) As String 'free low price cabins sum
Dim BNSum As Integer 'booked normal cabins sum
Dim KLSum As Integer 'booked komf/lux cabins sum
Dim FNSum As Integer 'free normal cabins sum
Dim FKLSum As Integer 'free komf/lux cabins sum
Dim FLPSum As Integer 'free low price cabins sum
startI = 1
'importing main ST screen
For i = StartRowST To EndRowST
CurrentRow = DAT.Cells(Rows.count, 1).End(xlUp).Row + 1
'<-------- Sail.Time: X -------->
If startI = 1 Then
'do nothing
Else
SendStr "X", 25, 31
Send "enter"
'
'
End If
'A date of entry - todaysdate
DAT.Range("A" & CurrentRow) = TodaysDate
'B compnay - CompanyComboBox
DAT.Range("B" & CurrentRow) = CompanyID
'C Dep
FromAS i, 6, 9
Dep = Left(From, 3)
DAT.Range("C" & CurrentRow) = Dep
'D Arr
Arr = Right(From, 3)
DAT.Range("D" & CurrentRow) = Arr
'E Dep date - CurrentDate
DAT.Range("E" & CurrentRow) = CurrentDate
'F Weekday
'FromAS i, 27, 2
'WeekD = From
DAT.Range("F" & CurrentRow) = Weekday(CurrentDate)
'G Time
FromAS i, 32, 5
DepTime = Replace(From, ".", ":")
DAT.Range("G" & CurrentRow) = DepTime
'Z Dep timeframe
If DepTime >= TimeValue("05:00:00") And DepTime < TimeValue("13:00:00") Then
DAT.Range("Z" & CurrentRow) = "Morning"
ElseIf DepTime >= TimeValue("13:00:00") And DepTime < TimeValue("19:00:00") Then
DAT.Range("Z" & CurrentRow) = "Afternoon"
ElseIf DepTime >= TimeValue("19:00:00") And DepTime < TimeValue("00:00:00") Then
DAT.Range("Z" & CurrentRow) = "Evening"
ElseIf DepTime >= TimeValue("00:00:00") And DepTime < TimeValue("05:00:00") Then
DAT.Range("Z" & CurrentRow) = "Night"
End If
'H Ship
FromAS i, 39, 2
Ship = From
DAT.Range("H" & CurrentRow) = Ship
'I WL
FromAS i, 59, 3
If Trim(From) <> "" Then WL = From
DAT.Range("I" & CurrentRow) = WL
'J Canc
FromAS i, 72, 4
If Trim(From) <> "" Then Canc = From
DAT.Range("J" & CurrentRow) = From
If DAT.Range("J" & CurrentRow) <> "CANC" Then
'K - Price
FromAS i, 85, 4
Price = Trim(From)
DAT.Range("K" & CurrentRow) = Price
'L - Currency from CurrencyComboBox
DAT.Range("L" & CurrentRow) = Curr
'<-------- Cabin-Av: B -------->
SendStr "B", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'M booked PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
BookedPax = Trim(From)
Else
BookedPax = 0
End If
DAT.Range("M" & CurrentRow) = BookedPax
'T - Booked Cab
BNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
BNAmo(j) = Trim(From)
If IsNumeric(Trim(BNAmo(j))) = True Then
'MsgBox "Right(Trim(Typ(j)), 1) = " & Right(Trim(Typ(j)), 1) & vbCrLf & "Trim(Typ(j) = " & Trim(Typ(j))
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
BNSum = BNSum + CInt(BNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & BNAmo(j)
Next j
DAT.Range("T" & CurrentRow) = BNSum
'U - Booked K/L Cab
KLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
KLAmo(j) = Trim(From)
If IsNumeric(Trim(KLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
KLSum = KLSum + CInt(KLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & KLAmo(j)
Next j
DAT.Range("U" & CurrentRow) = KLSum
'<-------- Cabin-Av: X -------->
SendStr "X", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'R free PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreePAX = Trim(From)
Else
FreePAX = 0
End If
DAT.Range("R" & CurrentRow) = FreePAX
'V - Free Cabins
FNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FNAmo(j) = Trim(From)
If IsNumeric(Trim(FNAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L" Or Trim(Typ(j)) <> "SU4") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
FNSum = FNSum + CInt(FNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FNAmo(j)
Next j
DAT.Range("V" & CurrentRow) = FNSum
'W - Free K/L Cab
FKLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
FKLAmo(j) = Trim(From)
If IsNumeric(Trim(FKLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L" Or Trim(Typ(j)) = "SU4") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
FKLSum = FKLSum + CInt(FKLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FKLAmo(j)
Next j
DAT.Range("W" & CurrentRow) = FKLSum
'<-------- Cabin-Av: L -------->
SendStr "L", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'S - Free LP PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreeLPpax = Trim(From)
Else
FreeLPpax = 0
End If
DAT.Range("S" & CurrentRow) = FreeLPpax
'X - Free LP Cab
FLPSum = 0
x = 0
For j = 0 To 19
FromAS 4, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FLPAmo(j) = Trim(From)
If IsNumeric(Trim(FLPAmo(j))) = True Then
If Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL" Then
FLPSum = FLPSum + CInt(FLPAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FLPAmo(j)
Next j
DAT.Range("X" & CurrentRow) = FLPSum
'<--------Deck-Av: X -------->
SendStr "X", 25, 54
Send "Enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Y Free Deck
FromAS i, 32, 3
Deck = Trim(From)
DAT.Range("Y" & CurrentRow) = Deck
'<-------- Query -------->
Send "pf3"
Send "pf3"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "6", 20, 7
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "2", 5, 26
SendStr "KOORDINAT", 9, 28
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Send "pf4"
SendStr "2A_01GREG", 11, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 13, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Dim SplQ() As String
SplQ() = Split(CheckDate, ".")
DateQ = SplQ(2) & "-" & SplQ(1) & "-" & SplQ(0)
SendStr DateQ, 7, 36
SendStr Dep, 8, 36
SendStr Arr, 9, 36
SendStr DepTime, 10, 36
'
'
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLOIA.WaitForInputReady
SendStr "'01' ", 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'N Booked MIS 1
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS1 = Trim(From)
Else
MIS1 = 0
End If
Else
MIS1 = 0
End If
DAT.Range("N" & CurrentRow) = MIS1
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'10' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'O MIS 10
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS10 = Trim(From)
Else
MIS10 = 0
End If
Else
MIS10 = 0
End If
DAT.Range("O" & CurrentRow) = MIS10
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'20' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'P MIS 20
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS20 = Trim(From)
Else
MIS20 = 0
End If
Else
MIS20 = 0
End If
DAT.Range("P" & CurrentRow) = MIS20
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'30' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Q MIS 30
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS30 = Trim(From)
Else
MIS30 = 0
End If
Else
MIS30 = 0
End If
DAT.Range("Q" & CurrentRow) = MIS30
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf12"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady (750)
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "N", 5, 29
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "13", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
CheckResource
If CheckResource = True Then
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
Else
MsgBox "Error. Not in ST. Unlock book window, and go to ST. If macro starts, leave it.", vbOKOnly, "Error"
End If
End If
'
'
startI = startI + 1
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
'<------------------------------- START, STOP FUNCTIONS -------------------------------------
'
' Set up fields need to link to 5250 session - Copy this block into any new Screen Scrapper macro as is
'
Sub ObjGetExtra()
DAT.Unprotect ("Coordination")
'DAT.Select
Set autECLSession = CreateObject("pcomm.auteclsession")
Set autECLPS = CreateObject("PCOMM.autECLPS")
Set autECLOIA = CreateObject("Pcomm.autecloia")
'Set autECLConnList = CreateObject("PCOMM.autECLConnList")
End Sub
Sub ObjEndExtra()
Set autECLSession = Nothing
Set autECLPS = Nothing
Set autECLOIA = Nothing
'Set autECLConnList = Nothing
DAT.Protect ("Coordination")
End Sub
'<------------------------------ FUNCTIONS FOR AS400 PROCESSING --------------------------------
'
' Put the value on the 5250 screen at the position specified
'
Function SendStr(ByVal Data As String, ByVal Row As Long, ByVal Col As Long)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos Row, Col
autECLSession.autECLPS.SendKeys Data, Row, Col
End Function
'
' Read a string from the 5250 screen strarting at the position specified
'
Function FromAS(ByVal Row As Long, ByVal Col As Long, ByVal Lenght As Long) As String
autECLSession.autECLOIA.WaitForInputReady
From = autECLSession.autECLPS.GetText(Row, Col, Lenght)
End Function
'
' Sent special keys to the session (function keys, enter, etc)
'
Function Send(Key As String)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[" & Key & "]"
End Function
' Check if in Sailing Timetable
Function CheckResource() As Boolean
FromAS 2, 20, 7
'
'
If Trim(From) = "SAILING" Then
FromAS 4, 11, 5
'
'
'
If Trim(From) = "Route" Then
'do nothing
CheckResource = True
Else
FromAS 4, 2, 3
'
'
If Trim(From) = "Seq" Then
Send "pf3"
CheckResource = True
End If
End If
Else
CheckResource = False
End If
End Function
'the form starting the comm session is here
'StartImport form code
'
Public SessionString As String
'Public handleConn As Byte
Private Sub RunButton_Click()
If CompanyComboBox <> "select" Then
If CompanyComboBox = "TT" And CurrencyComboBox <> "select" Then
If SessionString <> "" Then
'proper start sequence
Call ObjGetExtra
autECLSession.SetConnectionByname (SessionString)
autECLPS.SetConnectionByname (SessionString)
'autECLConnList.Refresh
autECLOIA.SetConnectionByname (SessionString)
If autECLSession.commstarted = False Then
MsgBox "There does not appear to be a session '" & SessionString & "'. Please Check and try again.", vbOKOnly, "Error"
Call ObjEndExtra
End If
Call CheckResource
If CheckResource = True Then
CompanyID = CompanyComboBox
Curr = CurrencyComboBox
StartDate = FromDateF
EndDate = ToDateF
Unload Me
Else
MsgBox "You are not in ST, please start ST in choosen session and start again.", vbOKOnly, "Error"
End If
Else
MsgBox "No Session button choosen.", vbOKOnly, "Error"
End If
ElseIf CompanyComboBox <> "TT" Then
CompanyID = CompanyComboBox
CurrencyComboBox = "EUR"
StartDate = FromDateF
EndDate = ToDateF
Unload Me
End If
Else
MsgBox "Nothing selected to be done", vbOKOnly, "Error"
End If
End Sub
Private Sub Session1_Click()
If Session1 = True Then
SessionString = "A"
'handleConn = 1
Session2 = False
Session3 = False
End If
End Sub
Private Sub Session2_Click()
If Session2 = True Then
SessionString = "B"
'handleConn = 2
Session1 = False
Session3 = False
End If
End Sub
Private Sub Session3_Click()
If Session3 = True Then
SessionString = "C"
'handleConn = 3
Session1 = False
Session2 = False
End If
End Sub
Private Sub CompanyComboBox_Change()
If CompanyComboBox = "TT" Then CurrencyComboBox.value = "select"
End Sub
Private Sub CancelButton_Click()
UserForm_QueryClose 0, 0
End Sub
Private Sub UserForm_Initialize()
'Company choice
With Me.CompanyComboBox
.AddItem "TT"
'rest deleted
End With
'Currency choice
With Me.CurrencyComboBox
.AddItem "EUR"
'rest deleted
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Call ObjEndExtra
Cancel = True
Unload Me
MsgBox "You ended. Thank you.", vbOKOnly, "Exit"
End
End If
End Sub
everywhere where you see in two lines: '
there should be some error handling like (above from code):
If not autECLOIA.InputInhibited = 0 Then
send "reset/ctrl"
end if
but it doesn't work - generating object errors
excel vba automation screen-scraping ibm-midrange
This question already has an answer here:
How to make SendKeys act Synchronously in IBM Host Access Library
1 answer
I'm running an excel automation macro to read IbM as400 terminal window data. My macro is running faster than the terminal window causing sometimes the autECLOIA console msg system to stop with a red X SYSTEM stop message.
I tried to include in my code the
If not autECLOIA.InputInhibited = 0 Then
statement, but failed with error msg's.
Could someone help me?
Option Explicit
'
'<------------- Definitions --------------------------------------------------------------------
'
'main sheet and connectivity declarations
Public DAT As Worksheet
Public CurrentRow As Long
Public autECLSession As Object
Public autECLPS As Object
Public autECLOIA As Object
Public autECLConnList As Object
'main declarations used by forms
Public CompanyID As String
Public Cancel As Boolean
Public Curr As String
Public Route1 As String, Route2 As String
'date variable definitions for entire programm
Public TodaysDate As Date
Public TodaysDateShort As String
Public TodaysDateAS As String
Public TodaysDateQuery As String
Public StartDate As Date
Public EndDate As Date
Public EndDateShort As String
Public EndDateAS As String
Public EndDateQuery As String
Public dateVariable As Date
Public TimeNow As String
Public CurrentDate As Date
Public DateTime As String
Public DateQ As String
'other declarations - minor
Public From As String
Public StartRowST As Byte
Public CountDep As Byte
Public EndRowST As Byte
Public myNewRangeSize As String
'
'<------------- Main subroutine ----------------------------------------------------------------
'
Sub Start()
'definitions and for initialisation
Set DAT = Worksheets("DATA")
Load StartImport
StartImport.Show
If Cancel = True Then Exit Sub
'Accordingly to currency the route changes
If Curr = "PLN" Then
Route1 = "SWITRE"
Route2 = "TRESWI"
Else
Route1 = "KONTRE"
Route2 = "TREKON"
End If
'data transfer functions
'set and format dates
StartEndFormatDates
'start import
If CompanyID = "TT" Then
'code for importing TT-Line data kontinent to trelleborg
CurrentDate = StartDate
Do Until DateValue(CurrentDate) = DateValue(DateAdd("d", 1, EndDate))
EnterSailingTimetableCountOneDaysDepartures Route1, CurrentDate
'MsgBox "CurrentDate = " & CurrentDate & _
'vbCrLf & "StartRowST = " & StartRowST & _
'vbCrLf & "CountDep = " & CountDep & _
'vbCrLf & "EndRowST = " & EndRowST
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route1, CurrentDate
End If
'switching route
EnterSailingTimetableCountOneDaysDepartures Route2, CurrentDate
If StartRowST = 0 And EndRowST = 0 Then
'do nothing
Else
ImportMainST Route2, CurrentDate
End If
CurrentDate = DateAdd("d", 1, CurrentDate)
Loop
Else
'enter here code for importing other data
End If
Dim myNewRangeSize As Long
myNewRangeSize = DAT.Range("A1000000").End(xlUp).Row
DAT.ListObjects("DataTable").Resize Range("$A$1:$Z$" & myNewRangeSize)
End Sub
'
'<------------- Main functions -----------------------------------------------------------------
'
'formats start and end dates to 3 formats = Human, AS400 and Query
Function StartEndFormatDates()
'Work on todays date
TodaysDate = Format(Now, "dd.mm.yyyy")
TodaysDateShort = Format(TodaysDate, "dd.mm.yy")
TodaysDateAS = Format(TodaysDate, "ddmmyy")
Dim DateSplit() As String
DateSplit() = Split(TodaysDate, ".")
TodaysDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'Go to calendar to pick a date for outbound
'AdvancedCalendar 'checked
'Check if any date chosen from calendar
If EndDate < TodaysDate Then 'if user closes calendar without picking a date the program ends here
'SendKeys2Extra "[pf3]"
MsgBox ("You ended. Thank you.")
Call ObjEndExtra
Exit Function
End If
'EndDate = Format(dateVariable, "dd.mm.yyyy")
EndDateShort = Format(EndDate, "dd.mm.yy")
EndDateAS = Format(EndDate, "ddmmyy")
DateSplit() = Split(EndDate, ".")
EndDateQuery = DateSplit(2) & "-" & DateSplit(1) & "-" & DateSplit(0)
'DispMsg (EndDate)
'time now
TimeNow = Format(Now, "hh:mm")
End Function
'enters ST in book window on given route and date --> counts first ST row and the number of departures
Function EnterSailingTimetableCountOneDaysDepartures(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ here I would want something like this @@@@@@@@@@@@@@@@@@@@@@@@@:
'If not autECLOIA.InputInhibited = 0 Then
' send "reset/ctrl"
'end if
'<=================================== but it doesn't work - generating object errors
'define variables
StartRowST = 0
CountDep = 0
EndRowST = 0
DateTime = ""
Dim i As Byte, stopif As Boolean
stopif = False
'start loop through ST screen to compare dates and time
For i = 1 To 18
autECLSession.autECLOIA.WaitForInputReady
'
'
FromAS 5 + i, 17, 8
'MsgBox "In search for last row:" & _
'vbCrLf & "From = " & CDate(Format(From, "dd.mm.yyyy")) & _
'vbCrLf & "Checkdate+1 day = " & CDate(DateAdd("d", 1, CheckDate))
Dim Spl() As String
Spl() = Split(From, ".")
From = Spl(0) & "." & Spl(1) & ".20" & Spl(2)
If CDate(From) = CDate(DateAdd("d", 1, CheckDate)) Then
'counts where is last Row in ST
If EndRowST > 0 Then
EndRowST = EndRowST - 1
Exit For
Else
Exit For
End If
Else
'read and set DateTime for determininig first row in ST
'FromAS 5 + i, 17, 8
DateTime = Format(From, "dd.mm.yyyy")
FromAS 5 + i, 32, 5
DateTime = DateTime & " " & Replace(From, ".", ":")
'MsgBox "DateTime = " & DateTime & _
'vbCrLf & "CheckDate = " & CheckDate & _
'vbCrLf & "Todaysdate+TimeNow = " & TodaysDate & " " & TimeNow
'check if DateTime read from ST bigger then Now - if so then counting first row and departures
If (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
StartRowST = 5 + i
CountDep = CountDep + 1
EndRowST = StartRowST
ElseIf (CDate(DateTime) < CDate(TodaysDate & " " & TimeNow)) And StartRowST = 0 Then
stopif = True
ElseIf (CDate(DateTime) > CDate(TodaysDate & " " & TimeNow)) And StartRowST > 0 Then
CountDep = CountDep + 1
End If
If stopif = False Then
EndRowST = EndRowST + 1
End If
End If
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
Function ImportMainST(Rou As String, CheckDate As Date)
'get into ST
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
'
'
Dim i As Byte, j As Integer, x As Integer, y As Byte, startI As Integer
Dim Dep As String, Arr As String, WeekD As String, DepTime As String, Ship As String, _
WL As String, Canc As String, Price As String, BookedPax As String, Deck As String, _
FreePAX As String, FreeLPpax As String, MIS1 As Integer, MIS10 As Integer, _
MIS20 As Integer, MIS30 As Integer ', BPax As Integer
Dim Typ(19) As String
Dim BNAmo(19) As String 'booked normal cabins - type and amount
Dim KLAmo(19) As String 'booked komf/lux cabins sum
Dim FNAmo(19) As String 'free normal cabins sum
Dim FKLAmo(19) As String 'free komf/lux cabins sum
Dim FLPAmo(19) As String 'free low price cabins sum
Dim BNSum As Integer 'booked normal cabins sum
Dim KLSum As Integer 'booked komf/lux cabins sum
Dim FNSum As Integer 'free normal cabins sum
Dim FKLSum As Integer 'free komf/lux cabins sum
Dim FLPSum As Integer 'free low price cabins sum
startI = 1
'importing main ST screen
For i = StartRowST To EndRowST
CurrentRow = DAT.Cells(Rows.count, 1).End(xlUp).Row + 1
'<-------- Sail.Time: X -------->
If startI = 1 Then
'do nothing
Else
SendStr "X", 25, 31
Send "enter"
'
'
End If
'A date of entry - todaysdate
DAT.Range("A" & CurrentRow) = TodaysDate
'B compnay - CompanyComboBox
DAT.Range("B" & CurrentRow) = CompanyID
'C Dep
FromAS i, 6, 9
Dep = Left(From, 3)
DAT.Range("C" & CurrentRow) = Dep
'D Arr
Arr = Right(From, 3)
DAT.Range("D" & CurrentRow) = Arr
'E Dep date - CurrentDate
DAT.Range("E" & CurrentRow) = CurrentDate
'F Weekday
'FromAS i, 27, 2
'WeekD = From
DAT.Range("F" & CurrentRow) = Weekday(CurrentDate)
'G Time
FromAS i, 32, 5
DepTime = Replace(From, ".", ":")
DAT.Range("G" & CurrentRow) = DepTime
'Z Dep timeframe
If DepTime >= TimeValue("05:00:00") And DepTime < TimeValue("13:00:00") Then
DAT.Range("Z" & CurrentRow) = "Morning"
ElseIf DepTime >= TimeValue("13:00:00") And DepTime < TimeValue("19:00:00") Then
DAT.Range("Z" & CurrentRow) = "Afternoon"
ElseIf DepTime >= TimeValue("19:00:00") And DepTime < TimeValue("00:00:00") Then
DAT.Range("Z" & CurrentRow) = "Evening"
ElseIf DepTime >= TimeValue("00:00:00") And DepTime < TimeValue("05:00:00") Then
DAT.Range("Z" & CurrentRow) = "Night"
End If
'H Ship
FromAS i, 39, 2
Ship = From
DAT.Range("H" & CurrentRow) = Ship
'I WL
FromAS i, 59, 3
If Trim(From) <> "" Then WL = From
DAT.Range("I" & CurrentRow) = WL
'J Canc
FromAS i, 72, 4
If Trim(From) <> "" Then Canc = From
DAT.Range("J" & CurrentRow) = From
If DAT.Range("J" & CurrentRow) <> "CANC" Then
'K - Price
FromAS i, 85, 4
Price = Trim(From)
DAT.Range("K" & CurrentRow) = Price
'L - Currency from CurrencyComboBox
DAT.Range("L" & CurrentRow) = Curr
'<-------- Cabin-Av: B -------->
SendStr "B", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'M booked PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
BookedPax = Trim(From)
Else
BookedPax = 0
End If
DAT.Range("M" & CurrentRow) = BookedPax
'T - Booked Cab
BNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
BNAmo(j) = Trim(From)
If IsNumeric(Trim(BNAmo(j))) = True Then
'MsgBox "Right(Trim(Typ(j)), 1) = " & Right(Trim(Typ(j)), 1) & vbCrLf & "Trim(Typ(j) = " & Trim(Typ(j))
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
BNSum = BNSum + CInt(BNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & BNAmo(j)
Next j
DAT.Range("T" & CurrentRow) = BNSum
'U - Booked K/L Cab
KLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
KLAmo(j) = Trim(From)
If IsNumeric(Trim(KLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
KLSum = KLSum + CInt(KLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & KLAmo(j)
Next j
DAT.Range("U" & CurrentRow) = KLSum
'<-------- Cabin-Av: X -------->
SendStr "X", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'R free PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreePAX = Trim(From)
Else
FreePAX = 0
End If
DAT.Range("R" & CurrentRow) = FreePAX
'V - Free Cabins
FNSum = 0
x = 0
For j = 0 To 19
FromAS 5, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FNAmo(j) = Trim(From)
If IsNumeric(Trim(FNAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) <> "K" Or Right(Trim(Typ(j)), 1) <> "L" Or Trim(Typ(j)) <> "SU4") And (Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL") Then
FNSum = FNSum + CInt(FNAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FNAmo(j)
Next j
DAT.Range("V" & CurrentRow) = FNSum
'W - Free K/L Cab
FKLSum = 0
x = 0
For j = 0 To 19
FromAS i, 32 + x, 4
FKLAmo(j) = Trim(From)
If IsNumeric(Trim(FKLAmo(j))) = True Then
If (Right(Trim(Typ(j)), 1) = "K" Or Right(Trim(Typ(j)), 1) = "L" Or Trim(Typ(j)) = "SU4") And (Trim(Typ(j)) <> "PULL" Or Trim(Typ(j)) <> "LOUN") Then
FKLSum = FKLSum + CInt(FKLAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FKLAmo(j)
Next j
DAT.Range("W" & CurrentRow) = FKLSum
'<-------- Cabin-Av: L -------->
SendStr "L", 25, 43
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'S - Free LP PAX
FromAS i, 27, 3
If IsNumeric(Trim(From)) = True Then
FreeLPpax = Trim(From)
Else
FreeLPpax = 0
End If
DAT.Range("S" & CurrentRow) = FreeLPpax
'X - Free LP Cab
FLPSum = 0
x = 0
For j = 0 To 19
FromAS 4, 32 + x, 4
Typ(j) = Trim(From)
FromAS i, 32 + x, 4
FLPAmo(j) = Trim(From)
If IsNumeric(Trim(FLPAmo(j))) = True Then
If Trim(Typ(j)) <> "LOUN" Or Trim(Typ(j)) <> "PULL" Then
FLPSum = FLPSum + CInt(FLPAmo(j))
End If
End If
x = x + 5
'MsgBox Typ(j) & " = " & FLPAmo(j)
Next j
DAT.Range("X" & CurrentRow) = FLPSum
'<--------Deck-Av: X -------->
SendStr "X", 25, 54
Send "Enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Y Free Deck
FromAS i, 32, 3
Deck = Trim(From)
DAT.Range("Y" & CurrentRow) = Deck
'<-------- Query -------->
Send "pf3"
Send "pf3"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "6", 20, 7
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "2", 5, 26
SendStr "KOORDINAT", 9, 28
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Send "pf4"
SendStr "2A_01GREG", 11, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 13, 3
Send "enter"
autECLSession.autECLOIA.WaitForInputReady
'
'
Dim SplQ() As String
SplQ() = Split(CheckDate, ".")
DateQ = SplQ(2) & "-" & SplQ(1) & "-" & SplQ(0)
SendStr DateQ, 7, 36
SendStr Dep, 8, 36
SendStr Arr, 9, 36
SendStr DepTime, 10, 36
'
'
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLOIA.WaitForInputReady
SendStr "'01' ", 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'N Booked MIS 1
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS1 = Trim(From)
Else
MIS1 = 0
End If
Else
MIS1 = 0
End If
DAT.Range("N" & CurrentRow) = MIS1
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'10' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'O MIS 10
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS10 = Trim(From)
Else
MIS10 = 0
End If
Else
MIS10 = 0
End If
DAT.Range("O" & CurrentRow) = MIS10
'
'
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'20' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'P MIS 20
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS20 = Trim(From)
Else
MIS20 = 0
End If
Else
MIS20 = 0
End If
DAT.Range("P" & CurrentRow) = MIS20
Send "pf3"
autECLSession.autECLPS.SetCursorPos 12, 35
autECLSession.autECLPS.SetCursorPos 12, 35
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "'30' ", 12, 35
Send "pf5"
autECLSession.autECLOIA.WaitForInputReady
'
'
'Q MIS 30
FromAS 6, 7, 1
If IsNumeric(From) Then
FromAS 7, 41, 3
If Trim(From) <> "" Then
MIS30 = Trim(From)
Else
MIS30 = 0
End If
Else
MIS30 = 0
End If
DAT.Range("Q" & CurrentRow) = MIS30
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf12"
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady (750)
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "N", 5, 29
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
Send "pf3"
autECLSession.autECLOIA.WaitForInputReady
'
'
SendStr "1", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
SendStr "13", 20, 7
Send "enter"
'
'
autECLSession.autECLOIA.WaitForInputReady
CheckResource
If CheckResource = True Then
SendStr Left(Rou, 3) & Right(Rou, 3), 5, 9
SendStr Format(CheckDate, "ddmmyy"), 5, 23
Send "enter"
Else
MsgBox "Error. Not in ST. Unlock book window, and go to ST. If macro starts, leave it.", vbOKOnly, "Error"
End If
End If
'
'
startI = startI + 1
Next i
'exits ST details to first ST screen to be ready for checking next date
Send "pf3"
End Function
'<------------------------------- START, STOP FUNCTIONS -------------------------------------
'
' Set up fields need to link to 5250 session - Copy this block into any new Screen Scrapper macro as is
'
Sub ObjGetExtra()
DAT.Unprotect ("Coordination")
'DAT.Select
Set autECLSession = CreateObject("pcomm.auteclsession")
Set autECLPS = CreateObject("PCOMM.autECLPS")
Set autECLOIA = CreateObject("Pcomm.autecloia")
'Set autECLConnList = CreateObject("PCOMM.autECLConnList")
End Sub
Sub ObjEndExtra()
Set autECLSession = Nothing
Set autECLPS = Nothing
Set autECLOIA = Nothing
'Set autECLConnList = Nothing
DAT.Protect ("Coordination")
End Sub
'<------------------------------ FUNCTIONS FOR AS400 PROCESSING --------------------------------
'
' Put the value on the 5250 screen at the position specified
'
Function SendStr(ByVal Data As String, ByVal Row As Long, ByVal Col As Long)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SetCursorPos Row, Col
autECLSession.autECLPS.SendKeys Data, Row, Col
End Function
'
' Read a string from the 5250 screen strarting at the position specified
'
Function FromAS(ByVal Row As Long, ByVal Col As Long, ByVal Lenght As Long) As String
autECLSession.autECLOIA.WaitForInputReady
From = autECLSession.autECLPS.GetText(Row, Col, Lenght)
End Function
'
' Sent special keys to the session (function keys, enter, etc)
'
Function Send(Key As String)
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[" & Key & "]"
End Function
' Check if in Sailing Timetable
Function CheckResource() As Boolean
FromAS 2, 20, 7
'
'
If Trim(From) = "SAILING" Then
FromAS 4, 11, 5
'
'
'
If Trim(From) = "Route" Then
'do nothing
CheckResource = True
Else
FromAS 4, 2, 3
'
'
If Trim(From) = "Seq" Then
Send "pf3"
CheckResource = True
End If
End If
Else
CheckResource = False
End If
End Function
'the form starting the comm session is here
'StartImport form code
'
Public SessionString As String
'Public handleConn As Byte
Private Sub RunButton_Click()
If CompanyComboBox <> "select" Then
If CompanyComboBox = "TT" And CurrencyComboBox <> "select" Then
If SessionString <> "" Then
'proper start sequence
Call ObjGetExtra
autECLSession.SetConnectionByname (SessionString)
autECLPS.SetConnectionByname (SessionString)
'autECLConnList.Refresh
autECLOIA.SetConnectionByname (SessionString)
If autECLSession.commstarted = False Then
MsgBox "There does not appear to be a session '" & SessionString & "'. Please Check and try again.", vbOKOnly, "Error"
Call ObjEndExtra
End If
Call CheckResource
If CheckResource = True Then
CompanyID = CompanyComboBox
Curr = CurrencyComboBox
StartDate = FromDateF
EndDate = ToDateF
Unload Me
Else
MsgBox "You are not in ST, please start ST in choosen session and start again.", vbOKOnly, "Error"
End If
Else
MsgBox "No Session button choosen.", vbOKOnly, "Error"
End If
ElseIf CompanyComboBox <> "TT" Then
CompanyID = CompanyComboBox
CurrencyComboBox = "EUR"
StartDate = FromDateF
EndDate = ToDateF
Unload Me
End If
Else
MsgBox "Nothing selected to be done", vbOKOnly, "Error"
End If
End Sub
Private Sub Session1_Click()
If Session1 = True Then
SessionString = "A"
'handleConn = 1
Session2 = False
Session3 = False
End If
End Sub
Private Sub Session2_Click()
If Session2 = True Then
SessionString = "B"
'handleConn = 2
Session1 = False
Session3 = False
End If
End Sub
Private Sub Session3_Click()
If Session3 = True Then
SessionString = "C"
'handleConn = 3
Session1 = False
Session2 = False
End If
End Sub
Private Sub CompanyComboBox_Change()
If CompanyComboBox = "TT" Then CurrencyComboBox.value = "select"
End Sub
Private Sub CancelButton_Click()
UserForm_QueryClose 0, 0
End Sub
Private Sub UserForm_Initialize()
'Company choice
With Me.CompanyComboBox
.AddItem "TT"
'rest deleted
End With
'Currency choice
With Me.CurrencyComboBox
.AddItem "EUR"
'rest deleted
End With
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Call ObjEndExtra
Cancel = True
Unload Me
MsgBox "You ended. Thank you.", vbOKOnly, "Exit"
End
End If
End Sub
everywhere where you see in two lines: '
there should be some error handling like (above from code):
If not autECLOIA.InputInhibited = 0 Then
send "reset/ctrl"
end if
but it doesn't work - generating object errors
This question already has an answer here:
How to make SendKeys act Synchronously in IBM Host Access Library
1 answer
excel vba automation screen-scraping ibm-midrange
excel vba automation screen-scraping ibm-midrange
edited Mar 23 at 0:15
Grzesiek Hallomoto
asked Mar 23 at 0:10
Grzesiek HallomotoGrzesiek Hallomoto
112
112
marked as duplicate by Charles, Community♦ Mar 26 at 16:44
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Charles, Community♦ Mar 26 at 16:44
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The pace of your macro must be throttled by the speed of the terminal screen. I have been using a solution shown here: https://stackoverflow.com/a/33310031/3175562 to make the Automation calls wait for when the terminal is ready.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The pace of your macro must be throttled by the speed of the terminal screen. I have been using a solution shown here: https://stackoverflow.com/a/33310031/3175562 to make the Automation calls wait for when the terminal is ready.
add a comment |
The pace of your macro must be throttled by the speed of the terminal screen. I have been using a solution shown here: https://stackoverflow.com/a/33310031/3175562 to make the Automation calls wait for when the terminal is ready.
add a comment |
The pace of your macro must be throttled by the speed of the terminal screen. I have been using a solution shown here: https://stackoverflow.com/a/33310031/3175562 to make the Automation calls wait for when the terminal is ready.
The pace of your macro must be throttled by the speed of the terminal screen. I have been using a solution shown here: https://stackoverflow.com/a/33310031/3175562 to make the Automation calls wait for when the terminal is ready.
answered Mar 23 at 2:10
MikeMike
653519
653519
add a comment |
add a comment |