Help needed with syntax/logic in Attachmate macro
Help needed with syntax/logic in Attachmate macro
(OP)
Hello Again!
After a few years since my last post I've been able to adapt the original macro that was created with great help from the community and make it perform numerous functions. Now, I'm looking to essentially have an extension of that original macro in excel screen scrape some different data from the Attachmate session but have run into a roadblock with the logistics.
The below code (still a work in progress and apologies as the code feature was presenting an error) has 'PO' as the input from excel into Attachmate to begin the process. The Attachmate session will then return records based off the 'PO' value into rows 8-21 on the screen. The macro will go record by record and look for location 'S' to be null while location 'I' has a value, it will then use input the selection code 'I' value to move into another screen for that specific record. This secondary screen will have more detailed information which will be screen scraped into excel before sending the PF3 function key to return to the list of records. Once the macro reaches the last record in row 21, it will then use the PF8 function key to move onto the next page of records and will loop the process. The issue I am running into is that for records on the second screen the macro will use the 'I' value to go into a record's secondary screen and scrape the data correctly but the PF3 function key returns to the original/first page of records and would start looping through that page again rather than moving back to the second page and continuing on with the next record. There are no identifiers between the pages (i.e. a location in the session that says page 1 of 2 or something similar) which I could have the macro look for unfortunately so I'm thinking there needs to be syntax built into the macro to use the PF8 function key the necessary amount of times to return to the screen it left off on but I'm not familiar with what the best method would be or really how to do that. Any ideas are appreciated!
Sub RecordLookUp()
Dim Sessions, System As Object, Sess0 As Object, PO As String, WB As Workbook, WS As Worksheet
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Set WB = ActiveWorkbook
Set WS = Sheets("Look-up")
rw = 2
rw1 = 1
With Worksheets("Look-up")
Do
For X = rw To ActiveSheet.Rows.Count
PO = Left(Sheets("Look-up").Cells(X, 1).Value, 9)
If PO = "000000000" Then Exit Sub
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CD")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Input value from Excel to Attachmate
Sess0.Screen.MoveTo 3, 44
Sess0.Screen.SendKeys PO
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Do
For r = 8 To 21
dd = 1
S = Trim(Sess0.Screen.GetString(r, 33, 8))
I = Trim(Sess0.Screen.GetString(r, 2, 2))
ML = Trim(Sess0.Screen.GetString(2, 23, 7))
'If both S and I are null -> end
If S = "" And I = "" Then
Exit Do
'If S is null but I is not, move into secondary screen with more detailed information
ElseIf S = "" Then
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
If ML = "INQUIRY" Then
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(18, 64, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If
'Return to records screen
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Exit Do
End If
Next r
'Next page
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Next X 'next row/group
Loop
End With
End Sub
After a few years since my last post I've been able to adapt the original macro that was created with great help from the community and make it perform numerous functions. Now, I'm looking to essentially have an extension of that original macro in excel screen scrape some different data from the Attachmate session but have run into a roadblock with the logistics.
The below code (still a work in progress and apologies as the code feature was presenting an error) has 'PO' as the input from excel into Attachmate to begin the process. The Attachmate session will then return records based off the 'PO' value into rows 8-21 on the screen. The macro will go record by record and look for location 'S' to be null while location 'I' has a value, it will then use input the selection code 'I' value to move into another screen for that specific record. This secondary screen will have more detailed information which will be screen scraped into excel before sending the PF3 function key to return to the list of records. Once the macro reaches the last record in row 21, it will then use the PF8 function key to move onto the next page of records and will loop the process. The issue I am running into is that for records on the second screen the macro will use the 'I' value to go into a record's secondary screen and scrape the data correctly but the PF3 function key returns to the original/first page of records and would start looping through that page again rather than moving back to the second page and continuing on with the next record. There are no identifiers between the pages (i.e. a location in the session that says page 1 of 2 or something similar) which I could have the macro look for unfortunately so I'm thinking there needs to be syntax built into the macro to use the PF8 function key the necessary amount of times to return to the screen it left off on but I'm not familiar with what the best method would be or really how to do that. Any ideas are appreciated!
Sub RecordLookUp()
Dim Sessions, System As Object, Sess0 As Object, PO As String, WB As Workbook, WS As Worksheet
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Set WB = ActiveWorkbook
Set WS = Sheets("Look-up")
rw = 2
rw1 = 1
With Worksheets("Look-up")
Do
For X = rw To ActiveSheet.Rows.Count
PO = Left(Sheets("Look-up").Cells(X, 1).Value, 9)
If PO = "000000000" Then Exit Sub
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CD")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Input value from Excel to Attachmate
Sess0.Screen.MoveTo 3, 44
Sess0.Screen.SendKeys PO
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Do
For r = 8 To 21
dd = 1
S = Trim(Sess0.Screen.GetString(r, 33, 8))
I = Trim(Sess0.Screen.GetString(r, 2, 2))
ML = Trim(Sess0.Screen.GetString(2, 23, 7))
'If both S and I are null -> end
If S = "" And I = "" Then
Exit Do
'If S is null but I is not, move into secondary screen with more detailed information
ElseIf S = "" Then
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
If ML = "INQUIRY" Then
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(18, 64, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If
'Return to records screen
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
'Exit Do
End If
Next r
'Next page
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Next X 'next row/group
Loop
End With
End Sub
RE: Help needed with syntax/logic in Attachmate macro
Worked at a place that had DOZENS of screen-scrape macros, like your situation, in Excel. I started getting folks wanting selected data abc, from screen xyz, given list mno, thus generating macro qrs.
After a half-dozen of these requests, I wondered if I could make a generalized macro, where any complete screen could be specified by DATA, and the screen data output to a specific worksheet in the screen-scrape workbook given an input sheet specifying the SCREEN and the INPUT DATA TABLE.
It's much simpler to pick data columns in Excel to report than modifying an existing macro to define columns and rows to scrape.
Unfortunately, I've lost my MASTER.xlsm workbook.
That being said, you mention PF3 not getting you a second page. Did you mean PF8?
Okay I see you are using PF3 on subsequent pages. How does it work manually?
What method do you use manually? It is the manual process that the screen-navigation-code patterns.
You need some sort of indication when the paging complete. In my experience, the screens were designed with a MESSAGE area on the last row (usually row24 as I recall) and I accumulated a full list of all messages and subsequently coded as required by the message.
It all starts with a knowledge of these factors.
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
FAQ99-7950: Strategies for scraping in multiple screens
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
PF8 is like the next or next page function while PF3 is like the back function.
The manual process of it is that you would enter an input (designated by PO in this case) then hit enter to see a list of all records for that value; if there are more records that that screen can show then it will have multiple pages/screens you can tab through using PF8. This list view gives high level information of each record which isn't very helpful for what is needed in the extract. However you can also look at each record in more detail by using the selection code (designated I in this case) which will take you into a different screen with more data fields that are helpful but the only way to get back to the complete listing of records is by using the PF3 key which unfortunately takes you back to the first page of records (so if there are multiple pages of records this is where I'm running into the issue). For this macro it can go into that more detailed screen for any of the records on the first page of the list and retrieve the necessary information for each while going back to the listing without any issue but pages 2, 3, 4, and so on have the issue.
As an example, let's say records/rows 1 & 8 on page 1 of the listing have the null value for 'S' so the macro is recognizing it needs to go into the more detailed screen of the record and retrieve that information - no issues. The macro continues through all the records/rows on page 1 then moves to page 2 where you might see rows 5 & 6 have null values for 'S' - it will go into the detailed view of record 5 and pull that data just fine but the PF3 key takes you back to page 1 of 2 in the records list where it will then continue with the logic and end up recapturing the details from record 7 again on page 1. I need it to recognize that it left off on page 2 and so when it uses that PF3/back feature it automatically uses the PF8 key the necessary number of times to get back to the page it left off on (i.e. PF8 x1 if on page 2, PF8x2 if on page 3, etc.).
I do see that Page 1 has a message on line 22 essentially stating more data is available, meaning that another page of records can be tabbed to using PF8 but I don't think that using this identifier would help much as there could be multiple pages of data for one input so I'm not sure how the macro would recognize exactly which page it had left off on. It's kind of like forgetting your place in a book and re-reading portions of it except it never gets past a certain point (sounds a little like me reading some of the textbooks in college).
RE: Help needed with syntax/logic in Attachmate macro
Otherwise, you need to store a value the representing the Page Number and maybe even the row number that you last interrogated.
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
PF3 is the only one I see notated as a return function but that starts you back off at the first page/entries of whatever the previous screen was.
RE: Help needed with syntax/logic in Attachmate macro
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
RE: Help needed with syntax/logic in Attachmate macro
Then you can address screen-scraping design & code.
I can give you tips on specific questions, but I don't have the time to devote to examining your code and giving your feedback there. As I see things, I'll comment.
I'm hampered by the fact that I haven't coded a screen-scrape for close to a decade. I'm relying on what I can remember about 3270 terminal emulation. Your emulator might be different. And I have no access to Attachmate!Extra. Just what I can find by Googling. I'll do what I can for you.
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
Sub RecordLookUp()
Dim Sessions, System As Object, Sess0 As Object, PO As String, WB As Workbook, WS As Worksheet
Set System = CreateObject("EXTRA.System")
Set Sessions = System.Sessions
Set Sess0 = System.ActiveSession
Set WB = ActiveWorkbook
Set WS = Sheets("Look-up")
rw = 2
rw1 = 1
With Worksheets("Look-up")
Do '1
For X = rw To ActiveSheet.Rows.Count '2
PO = Left(Sheets("Look-up").Cells(X, 1).Value & "000000000", 9)
If PO = "000000000" Then Exit Sub
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("BA")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 5, 22
Sess0.Screen.SendKeys ("CD")
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Sess0.Screen.MoveTo 3, 44
Sess0.Screen.SendKeys PO
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
PG = Left(Sheets("Look-up").Cells(1, 2).Value & "0000", 4)
If PG = "0000" Then Exit Sub
PR = Sess0.Screen.GetString(8, 5, 4)
Sheets("Look-up").Cells(1, 2) = PR
Do '3
For r = 8 To 21 '4
dd = 1
S = Trim(Sess0.Screen.GetString(r, 33, 8))
I = Trim(Sess0.Screen.GetString(r, 2, 2))
If PG = PR Then '5
If S = "" And I = "" Then
Exit Do '6
ElseIf S = "" Then '6
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
ML = Trim(Sess0.Screen.GetString(2, 23, 27))
If ML = "INQUIRY" Then '7
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(8, 52, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else '7
CONT = Sess0.Screen.GetString(8, 18, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If '7
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
End If '6
Else '5
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
If S = "" And I = "" Then
Exit Do '8
ElseIf S = "" Then '8
Sess0.Screen.MoveTo 5, 18
Sess0.Screen.SendKeys I
Sess0.Screen.SendKeys ("<Enter>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
ML = Trim(Sess0.Screen.GetString(2, 23, 27))
If ML = "INQUIRY" Then '9
CONT = Sess0.Screen.GetString(4, 28, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(8, 52, 8)
Date2 = Sess0.Screen.GetString(18, 73, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(8, 23, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 78, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
Else '9
CONT = Sess0.Screen.GetString(8, 18, 4)
ID = Sess0.Screen.GetString(3, 44, 9)
ENTITY = Sess0.Screen.GetString(4, 9, 6)
PRDGRP = Sess0.Screen.GetString(4, 28, 6)
Date1 = Sess0.Screen.GetString(20, 21, 8)
Date2 = Sess0.Screen.GetString(20, 31, 8)
MCode = Sess0.Screen.GetString(4, 62, 2)
ISB = Sess0.Screen.GetString(9, 10, 8)
FR = Trim(Sess0.Screen.GetString(5, 51, 13))
MA = Sess0.Screen.GetString(5, 69, 1)
LA = Trim(Sess0.Screen.GetString(5, 12, 27))
SN = Sess0.Screen.GetString(9, 72, 9)
SR = Trim(Sess0.Screen.GetString(6, 14, 25))
CT = Trim(Sess0.Screen.GetString(6, 45, 25))
ST = Sess0.Screen.GetString(6, 77, 2)
ZP = Sess0.Screen.GetString(7, 6, 5)
rw1 = rw1 + 1
Sheets("Workbook").Cells(rw1, 1) = CONT
Sheets("Workbook").Cells(rw1, 2) = ID
Sheets("Workbook").Cells(rw1, 3) = ENTITY
Sheets("Workbook").Cells(rw1, 4) = PRDGRP
Sheets("Workbook").Cells(rw1, 5) = Date1
Sheets("Workbook").Cells(rw1, 6) = Date2
Sheets("Workbook").Cells(rw1, 7) = MCode
Sheets("Workbook").Cells(rw1, 8) = ISB
Sheets("Workbook").Cells(rw1, 9) = FR
Sheets("Workbook").Cells(rw1, 10) = MA
Sheets("Workbook").Cells(rw1, 11) = LA
Sheets("Workbook").Cells(rw1, 12) = SN
Sheets("Workbook").Cells(rw1, 13) = SR
Sheets("Workbook").Cells(rw1, 14) = CT
Sheets("Workbook").Cells(rw1, 15) = ST
Sheets("Workbook").Cells(rw1, 16) = ZP
End If '9
Sess0.Screen.SendKeys ("<Pf3>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
End If '8
End If '5
Next r '4
Sess0.Screen.SendKeys ("<Pf8>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
PR = Sess0.Screen.GetString(8, 5, 4)
Sheets("Look-up").Cells(1, 2) = PR
Loop '3
Sess0.Screen.SendKeys ("<Pf2>")
Do While Sess0.Screen.OIA.XStatus <> 0
DoEvents
Loop
Next X 'next row/group '2
Loop '1
End With
End Sub
RE: Help needed with syntax/logic in Attachmate macro
RE: Help needed with syntax/logic in Attachmate macro
CODE
I can see that you're using this cell to keep track of where you are in the sheet. Maybe your code needs to grab the initial value from the sheet before you begin you loop through that screen.
Regarding the CODE feature here, I rarely use the buttons, but if you do, you must FIRST SELECT the text you want in a CODE Window and then hit the CODE button. Otherwise, as I mostly do, put the TGML tag in yourself...
[code]
[/code]
...and then paste your procedure in between.
Once you get your paging working, i'll give you a few more ideas.
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
CODE
Now the issue is that the macro will use the reference value correctly, move to the Else '5 sequence correctly but will think that both S and I are null (when in fact they are not) which is causing it to exit the Do cycle. It shows that the r value is equal to the correct row it should read on that second page (r = 8) so I'm wondering if this needs to also be specified outside the loop.
CODE
RE: Help needed with syntax/logic in Attachmate macro
CODE
But what you can do is
1) UNCOMMENT that statement
2) Put a BREAK on that statement
3) Run to the BREAK, at which time, use the Watch Window to inspect the values stored in each if your variables.
FAQ707-4594: How to use the Watch Window as a Power Programming Tool
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
If I continue running the macro, everything else runs fine until it gets to page 2 where it will successfully screen scrape the new value for PG from Attachmate but yet again will get to the PG = PR statement and will show PG as the old value rather than registering what it stored in excel just before.
Basically I think whatever the value is at the start of the macro in the cell PG is linked to is what that value remains throughout the macro until I restart the macro with a new value in that cell. For example, first run of the macro PG is initially 0000, it will screen scrape and store 1234 but still reads it as 0000 so the macro ends. Second run of the macro it will read the 1234 stored in that cell now so PG = 1234, it will then see that matches all records on page one and executes the commands for that page correctly, then tabs to the next page of records and stores the new value 5678 and tries to loop - during the loop it still sees PG as equal to 1234 so it's continuously looping the pulls from page 1.
RE: Help needed with syntax/logic in Attachmate macro
Then PF8
Then store the CURRENT page number.
Notice that the FIRST page of any screen is a unique condition, that has no PREVIOUS value.
All this is part of screen navigation, including interrogating the message area after any codes that you send to the mainframe and performing appropriate steps. I notice that you are using a Do...Loop waiting for the mainframe to be ready to process any command. That's very astute.👍
Once you get your screen navigation code figured out, we might attempt modifying your code to simplify and streamline, if you care to do that.
Almost all of the screens that my users asked me to scrape were a one-screen process. So my paging was simpler. On very few occasions I encountered multiple screen situations and I can't remember any specifics from those encounters. I tend to think that the coding for those applications were all unique or COPY similar code and modify.
I kick myself for having lost my master workbook.
Here's a thought I just had.
In your process, you go to another screen based on values in the first screen. So what if you processed each screen separately, generating a list/table from the first screen and then processing that list/table to scrape the second screen?
Just a thought
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
Macro 1:
CODE
Macro 2:
CODE
RE: Help needed with syntax/logic in Attachmate macro
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
RE: Help needed with syntax/logic in Attachmate macro
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
CODE
While amending the second macro I'm now getting a compile error of 'Next without For' on the last Next syntax. Any ideas what I may not have closed out and what I'm missing? I've tried another End If above this but that will give another compile error of 'End If without block If' and any I try to remove give errors up to those points in the coding.
CODE
RE: Help needed with syntax/logic in Attachmate macro
I'm sure you've noticed that you have lots of repeated code. What sticks out the most is where you repeat PF8 one after the other. This is part of your screen navigation. These can probably be in a loop. Since I don't have access to your emulator, I don't know the logic of x repeats of PF8 or any other repeated command.
Then you have repeated use of scrape-and-store code. Those could be put in a separate procedure using module-level declarations for each variable used.
This will greatly simplify and minimize your code.
I'd like to see a pic of each screen and your "workbook" worksheet along with any explanation that would help me understand the screen navigation.
I didn't have the time today to scour your code to find the missing For.
Totally don't know what you mean by, "I realized the PG1-PG5 values..." and so on.
You have to reveal a LOT more about your screen navigation before I can be of specific help.
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
I've set the variables and inserted a loop for the PF8 keys which I think will work but I'll need to wait to test it as I am still encountering the For error and I cannot figure out where I've messed up the syntax.
RE: Help needed with syntax/logic in Attachmate macro
You have declared a workbook object and a worksheet object. But you fail to use them.
In this case, where you only reference ONE workbook and ONE worksheet, declaring object variables is really unnecessary. But lets go ahead and use them. I'll make a few minor changes to illustrate what I like to do. And I'm leaving out some code simply to emphasize these things.
CODE
Now here, starting sheet 4 I do not see "SUB" @ 6,2???
NOTICE:
1) when you use With..End With, the Reference, in this case the worksheet object, wsOutData, is implied by each DOT Reference (.Rows.Count & .Cells(X, 2).Value) to wsOutData within the block.
2) I'm using PutString to place data on the screen. Neither is a command sending data to the mainframe UNTIL you hit SendKeys "ENTER"
3) I've put in ALL of the Block Format at the appropriate indent. I make a practice of doing this each time I add a block so I greatly minimize having a For without Next or If without End If.
CODE
To exit a For...Next before the limit use an If test to Exit For.
CODE
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
I did have to make quite a few amendments to the code though. At the start of each new input search, it's running a loop of PF7 10 times in the Attachmate session because for whatever reason if I used PF7 only once or twice sometimes it would go back to the list of records for the previous input while other times it would somewhat get lost in the paging of the current record. This loop ensures it always resets to the first page of that input's records (barring any records with 10+ pages it might previously pull up). There was no key(s) to reset the screen and remove that previous search history without having to restart the session itself so I figured this was the quicker option although I would have liked it to work off of a loop based on the PG2 variable to page back the appropriate number of times when necessary. I did in fact try this and ran into the same issue as stated earlier where it goes into the wrong record or gets lost in the paging of the correct record.
"SUB" at 6,2 is correct, I edited this area in the screenshot due to some sensitive information.
I removed the second Do...Loop to give that a shot but it backs out to the first screen every time and then got a bit lost after that so I figured I'd better not fix something that's not broke for me right now.
Embedding the screen scrape macro in it's own sub and calling that into the main sub was a genius idea though so thanks so much for that! If you see any other places where I might be able to clean up feel free to let me know!
CODE
RE: Help needed with syntax/logic in Attachmate macro
Here's another tip, like polishing an apple and tuning the string to a perfect harmonic. It could be a constant labor of love.
Look for places where an object variable can save you multiple dot levels of reference. Here oScreen can replace Sess0.Screen.
CODE
These two FAQs ought to be helpful.
FAQ707-4105: How Can I Make My Code Run Faster?
FAQ707-4594: How to use the Watch Window as a Power Programming Tool
FYI: Most of my posting regarding the use of VBA code is in forum707: VBA Visual Basic for Applications (Microsoft).
It is just the honest truth that I found VBA and the Editor, were so much more superior to Extra VB and that Editor that I never wasted my time trying to learn the lesser of the two when I was ALWAYS using an Excel list to drive any process.
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!
RE: Help needed with syntax/logic in Attachmate macro
The stated goal is to remove as much DATA embedded in your code as possible and rather embed the data in one or more tables. Managing dozens of sets of values in a table used by one set of code is much easier than managing dozens of sets of code.
So the specific goal is to place the screen data in a table with headings like:
So in this case, making some assumptions...
Now I did this for every every single field on the screen and I had dozens of screens so defined in my table. And my corresponding worksheet had the same headings in the same order. So I would read down the table for the given screen and do a GetString according to the values in the table then a PutString in my worksheet.
On screens where there were a range of rows, all the single-row fields would be repeated for each row. The Type field was to either make the Excel column GENERAL for NUM or TEXT for CHR. If the leading ZERO is necessary, then TEXT/CHR.
Skip,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!