Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for capturing part of a screen in attachmate and saving to a file

Status
Not open for further replies.

vbnovice1

Programmer
May 1, 2006
9
GB
I have the following macro/script and need to add after every program (where I have left the spaces with *********************** either side where these commands need to go) an if command that if the macro finds text in the first 8 characters of this field to capture this info and save to a .txt file.

i.e screen

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

yyyyyyyy < --------------If text here it captures it if blank it carries on

the macro.

Thanks in advance here is the macro
Please let me know the commands to put in the gaps I have left!!!

==========================================================

Here Goes!!!



visual basic code:--------------------------------------------------------------------------------' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System ") ' Gets the system object
If (System is Nothing) Then
Msgbox "Could not create the EXTRA System object. Stopping macro playback."
STOP
End If
Set Sessions = System.Sessions

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
'--------------------------------------------------------------------------------
' Set the default wait timeout value
g_HostSettleTime = 3000 ' milliseconds

OldSystemTimeout& = System.TimeoutValue
If (g_HostSettleTime > OldSystemTimeout) Then
System.TimeoutValue = g_HostSettleTime
End If

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.ActiveSession
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

' This section of code contains the recorded events
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("PROGRAM1<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<COMMAND1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("COMMAND2<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right><Right><Left>COMMAND3<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND4<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Attn>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys ("PROGRAM2<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<COMMAND1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("COMMAND2<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND3<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND4<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Attn>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("PROGRAM3<Enter>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.Sendkeys("<COMMAND1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("COMMAND2<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND3<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND4<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("<Attn>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.Sendkeys("PROGRAM4<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<COMMAND1>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
********************************************************

********************************************************
Sess0.Screen.Sendkeys("COMMAND2<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND3<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right><Right><Right><Left><Left>COMMAND4<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Attn>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Pf5>")
Sess0.Screen.WaitHostQuiet (g_HostSettleTime)
Sess0.Screen.Sendkeys("PROGRAM5<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<COMMAND1>")
********************************************************

********************************************************
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("COMMAND2<Enter>")
********************************************************

********************************************************
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND3<Enter>")
********************************************************

********************************************************
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Right><Right><Right><Right><Right><Right>COMMAND4<Enter>")
********************************************************

********************************************************
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Attn>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

System.TimeoutValue = OldSystemTimeout
End Sub
 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx < ---there's text here are you ignoring it?


yyyyyyyy < --------------If text here it captures it if blank it carries on

Are you attempting to capture only lines with 8 characters?
What if there's more/less characters?

Have you looked around this forum... there's lots of examples doing variations of what your asking.

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
These threads may help to get you started.

thread99-468324
thread99-541119


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Basically, this macro is running commands on CA-7 job scheduling programs and what i need is if there is a failed job, i.e 8 characters in one part of the screen then it records this to a .txt file and if there are no job failures then it carries on with the other commands until it finds a job failure.
 
This will search the entire page. If it's just on a certain row, you can skip the for loop and just dial it in to the row/col it'll show at.
Code:
For y = 1 to YourRows
    TheInfo = Trim(Sess0.GetString(y,1,8))
    If Len(TheInfo) = 8 then
        'Code to save TheInfo to a file
    End If
Next


If it moves around but always appears after "xxxxxx..." then you could do this.
Code:
InfoNext = false
For y = 1 to YourRows
    If InfoNext Then
        TheInfo = Trim(Sess0.GetString(y,1,8)
    Else
        TheInfo = ""
    End If
    If Sess0.GetString(y,1,30) = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Then InfoNext = true
Next
 
Hi, Thanks for all your help I have coded this now, my next problem is that if there is a NO job down it displays "NO QUEUE RECORDS MATCH PARAMETERS ENTERED" and if there is a job down it displays "REQUEST COMPLETED AT 21:26:03 ON 06.124" how can I manipulate the code to search for NO QUEUE otherwise search REQUEST COMPLETE


Thanks is advance

 
If Sess0.GetString(x,y,16) = "NO QUEUE RECORDS" then
do something here
Else if Sess0.GetString(x,y,17) = "REQUEST COMPLETED" then
do something else
End If

replace x and y with the screen coords

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Mr.Milson Thanks for that hear is were I need to include your suggestion, I can't get it to work though.


'**** NEW CODE STARTS HERE ****

'Open file for Output (first close file in case already open from an aborted run)
Close #1
Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file
'First page
Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
If SearchComplete="" Then
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
Else
Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
End If
MyOutput$ = MyArea.Value
Write #1, MyOutput$
'While loop for subsequent pages
While SearchComplete=""
Sess0.Screen.Sendkeys("<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
If SearchComplete="" Then
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
Else
Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
End If
MyOutput$ = MyArea.Value
Write #1, MyOutput$
Wend

Close #1
'**** NEW CODE ENDS HERE ****
 
If SearchComplete.value="" Then
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
Else
Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
End If


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
That was wrong sorry you had that line correct.

What is it doing? grabbing the wrong area when it finds request complete?

Is this a scrolling screen?

try this

Dim SearchComplete as an Object then the following should always grab from the first page to the Request complete page.

'**** NEW CODE STARTS HERE ****

'Open file for Output (first close file in case already open from an aborted run)
Close #1
Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file

While SearchComplete=""
Sess0.Screen.Sendkeys("<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
MyOutput$ = Sess0.Screen.Area(7,1,22,79,,2).Value
Write #1, MyOutput$
SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
Wend

Close #1
'**** NEW CODE ENDS HERE ****


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
not having much luck here trying to hurry but try this


Code:
'Open file for Output (first close file in case already open from an aborted run)
    Close #1
    Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file

While Not Done
        MyOutput$ = Sess0.Screen.Area(7,1,22,79,,2).Value
        Write #1, MyOutput$
        Sess0.Screen.Sendkeys("<Pf8>")
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        if Sess0.Screen.Search("REQUEST COMPLETED").Value <> "" then Done = True
Wend
Close #1
If it doesn't work let me know whats happening

[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Ggggrrrr, Final answer

'**** NEW CODE STARTS HERE ****

'Open file for Output (first close file in case already open from an aborted run)
Close #1
Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file

'First page
Write #1, Sess0.Screen.Area(7,1,22,79,,2).Value

'following pages if any
While Sess0.Screen.Search("REQUEST COMPLETED").Value <> ""
Sess0.Screen.Sendkeys("<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Write #1, Sess0.Screen.Area(7,1,22,79,,2).Value
Wend
Close #1


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Is all it is saving to the .txt file is
"
"

and also it won't pf8 the page to the next page!!!

D'oh!!
 
try replacing

While Sess0.Screen.Search("REQUEST COMPLETED").Value <> ""

with

While Sess0.Screen.Search("REQUEST COMPLETED").Value = ""




[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Again sorry for all the confusion, I hope you've figured it out already but if not try this.[banghead]

Code:
'Open file for Output (first close file in case already open from an aborted run)
    Close #1
    Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file

'Write First page
Write #1, Sess0.Screen.Area(7,1,22,79,,2).Value

'Write following pages if any
While Sess0.Screen.Search("REQUEST COMPLETED").Value = ""  'if we see request complete it'll skip this loop
      Sess0.Screen.Sendkeys("<Pf8>")  'turn the page
      Sess0.Screen.WaitHostQuiet(g_HostSettleTime)   'give page time to load
      Write #1, Sess0.Screen.Area(7,1,22,79,,2).Value  'write the page
Wend   'Go to top of loop check for request complete on page just written
Close #1


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
Still struggling with this.

Here goes.

This is what I have done so far

'**** NEW CODE STARTS HERE ****
'Declarations
Dim SearchComplete As Object
Dim MySelection
Dim MyArea As Object

'Open file for Output (first close file in case already open from an aborted run)
Close #1
Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file
'First page
Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
If SearchComplete="" Then
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
Else
Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
End If
MyOutput$ = MyArea.Value
Write #1, MyOutput$
'While loop for subsequent pages
While SearchComplete=""
Sess0.Screen.Sendkeys("<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
If SearchComplete="" Then
Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
Else
Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
End If
MyOutput$ = MyArea.Value
Write #1, MyOutput$
Wend

Close #1
'**** NEW CODE ENDS HERE ****

This works fine for the LIST command in CA7, this is because this displays REQUEST COMPLETE when there is a job down, or a job isn't down.

So at R7,C2 you get
SJR0-00 REQUEST COMPLETED AT 22:30:18 ON 06.133 when no jobs down.

However in LQ,ST=x if job is down then this is fine.
at Rx,Cx.
SLIF-00 REQUEST COMPLETED AT 22:31:58 ON 06.133.

The problem is if a job isn't down you get.
At R3,C2
SLIF-19 NO QUEUE RECORDS MATCH PARAMETERS ENTERED.

Any ideas please!!

Thanks in advance.





 
This should located either a REQUEST COMPLETE or NO QUEUE RECORDS.

Code:
'Declarations
    Dim SearchComplete As Object
    Dim MySelection
    Dim MyArea As Object

'Open file for Output (first close file in case already open from an aborted run)
    Close #1
    Open "c:\jobs.txt" For Output As #1

'Check for "Request Completed" (for multiple pages) outputting each page to file
'First page
    Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
    If SearchComplete="" Then
        Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
    Else
        Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
    End If
    MyOutput$ = MyArea.Value
    Write #1, MyOutput$
'While loop for subsequent pages
    While SearchComplete=""
        Sess0.Screen.Sendkeys("<Pf8>")
        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
        Set SearchComplete = Sess0.Screen.Search("REQUEST COMPLETED")
        Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
        If SearchComplete="" Then
            Set SearchComplete = Sess0.Screen.Search("NO QUEUE RECORDS")
            Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
            If SearchComplete="" Then
                Set MyArea = Sess0.Screen.Area(7,1,22,79,,2)
            Else
                Set MyArea = Sess0.Screen.Area
            End If
        Else
            Set MyArea = Sess0.Screen.Area(7,1,SearchComplete.Bottom,79,,2)
        End If
        MyOutput$ = MyArea.Value
        Write #1, MyOutput$
    Wend

    Close #1
 
Excellent Thanks for all of your help.

Now for the next problem.

the output c:\jobs.txt looks like the following:

for example.

" MD265M00 MD264M00 SJR0-00 "
"MD91R501 MD92R501 SLIF-00 R"
" SLIF-19 "
" SLIF-19 "
" SJR0-00 "
" SLIF-19 "
" SLIF-19 "
" SLIF-19 "
" RJ220D30 JORP3D4A JP331D3A JP333D3A SJR0-00 "
" SLIF-19 "
" SLIF-19 "
" SLIF-19 "
" SJR0-00 "
" SLIF-19 "
" SLIF-19 "
" SLIF-19 "
" SJR0-00 "
" SLIF-19 "
" SLIF-19 "
" SLIF-19 "

I now need this output to be put in a template like this

so from the above

line 1 " MD265M00 MD264M00 SJR0-00 " is from the LIST command from U7CDC.

Is there anyway of making a template and telling the macro to input the jobs down under the following headers.

i.e

U7CDC
=====
LIST
====


HELD
====

SKEL
====

JCLO
====

This for each of the 5 CA7's

How would I code this and also list the jobs downwards rather than across the page.


Thanks in advance.
 
Do you find that information on the screen somewhere? If so is it always in the same place?

Is it based on how many times you hit PF8?

If it's always in the same place you can just do:
Code:
MyPage$ = Sess0.Screen.Area(1,1,1,5,,2)
Write #1, MyPage$
Write #1, MyOutput$
Write #1, ""

If you need to do it based on something then you can just code something to look for the information. This would take something similar to the SearchComplete.

Code:
Set SearchComplete = Sess0.Screen.Search("LIST")
If SearchComplete <> "" then MyPage$ = "LIST"
 
Is there anyway of setting these categories as fixed on the output.

i.e.

LIST
====
then jobs go here if any.

Also can is there anyway of outputting nothing if there are no jobs down.

as at the moment we get "" or "SLIF"


Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top