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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Caputring Data to a file using a macro

Status
Not open for further replies.

mytime21

Programmer
Apr 3, 2006
31
US
I have been able to record a macro that will run the report and stick it in the spooler for me. I need to be able to make the capture incoming data work while running a macro to be able to send the data to a file. I am a beginner in this. The data that goes to the file is variable and can range from about 20,000 lines to 30,000 lines. Can anyone help me to be able to capture the data from the spooler into a file using a macro???
 
Help file said:
Set rc = object.Area(StartRow,StartCol,EndRow,EndCol[,Page][,Type])

Element Description
Set The Set statement, required for assigning an object reference to a variable.
rc The object variable for referencing the returned object.
object The Screen object.
StartRow The row where the selection begins.
StartCol The column where the selection begins.
EndRow The row where the selection ends.
EndCol The column where the selection ends.
Page VT session only -- the screen page.
Type Determines how the coordinates of the Area object (top, left, bottom, right) are interpreted when the object is selected.

Set MyArea = MyScreen.Area(1,1,80,24 , ,)
The Type parameter accepts the following values.

Value Meaning
3 or xBLOCK The Area is selected as a rectangular range of characters. There is no line wrapping. This is the default.
2 or xSTREAM The Area is selected as a continuous stream of characters, from the top left coordinate to the bottom right coordinate. If the Area consists of more than one line, then the selection wraps to the right of each line.

so

linebuf$=Sess0.Screen.Area(row%,1,rows%,MaxColumns%,xBlock)

could be

linebuf$=Sess0.Screen.Area(row%,1,rows%,MaxColumns%,xStream)

but It will probably just return the same 35 rows. What a challenging question you have here MyTime. Thanks for jumping in CautionMP.


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


 
I can type "F1B" and jump to the bottom or just use the page up and page down keys. "F1T" takes me to the top of the report. I think using the browse may be easier to make this work. The lines on screen are always the same amount.

Thanks for all the help everyone. I am going to be out a lot of money to send everyone a free beer at their favorite place!
 
Here is maybe a better idea. I can actually make the macro run the report and then it can be displayed screen by screen. I can capture it each screen and then hit return. Any ideas on this working? The only problem is it is not necessarily going to be the same amount of screens each time.
 
to do screen by screen we just need to loop what we already have. Is there any indicatro as to when your viewing the last page (page 4 of 4, end of page)? If you let us know how you turn the page and someway of determining the last we can do a turn/grab page function.

roughly something like this

navigate to report
loop
GrabNTurn()
PrintToFile()
until last page

But you'll have to pretty detailed about
how to get there
how to turn the page
how to know its the last page
(can i turn beyond the last page? what the last screen looks like blank, any constants? headers\footers ect.)

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


 
The only way to recognize the end of the report would be to see that on the last screen there would be a line stating this: "1 Performance Monitor (kc version)"
That always appears at the end of the report. in order for me to go to the next screen I just hit the return key.
 
We can capture each screen from the beginning of the report until attachmate closes as far as I am concerned.
 
So I got this far with scrolling thing just trying to see what I could come up with. It gives me and error on line 92, which tells me it is out of string space. Is there any way to make the string space larger, like calling more memory allocated to it or something. Line 92 is the ScreenBuf$-ScreenBuf$+lineBuf$...etc

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 = 500        ' milliseconds

    OldSystemTimeout& = System.TimeoutValue
    If (g_HostSettleTime > OldSystemTimeout) Then
        System.TimeoutValue = g_HostSettleTime
    End If
' Name the variables
Dim rc%
Dim MaxColumn%
Dim row%
Dim MaxRows%
Dim filenum%
Dim Screenbuf$
Dim linebuf$
Dim FileName$

' 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.Connected = True	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("vista<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("rmd8940<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("2BLS&RMD1.<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("ma<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("spo<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("print<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("ryan mar<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("1<Ctrl+M>")	
	Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
	Sess0.Screen.Sendkeys("<Keypad 0>;<Keypad 2><Keypad 4><Keypad 0>;<Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad Enter><Keypad Enter><Keypad Enter><Keypad Enter>")	
        

        Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

	System.TimeoutValue = OldSystemTimeout


' Determine the size of the Presentation Space
MaxRows%=Sess0.Screen.Rows()
MaxColumns%=Sess0.Screen.Cols()
    


' Initialize variables to hold screen information
    Screenbuf$ = ""
    linebuf$ = Space$ (MaxColumns%)

' Copy the Presentation space
    For row% = 1 to MaxRows%
        ' Get a row of data from the host screen
        linebuf$ = Sess0.Screen.Area(row%,1,MaxRows%,MaxColumns%,xBlock)

        ' Store the line read into screenbuf$
        Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
    Next

' Get the next available file number
   filenum% = FreeFile

' Open the printer. To print to a file, set FileName$ to a file name.
' In this example, "\\TES\L4S_HP" is a network printer name.
' Change this to your printer name.

    FileName$ = "c:\temp\newTest1.txt"
    Open FileName$ For Output as filenum%

' Print the screen with a form feed
    Print # filenum%, screenbuf$; Chr$ (12)

'Close printer
    Close filenum%
End Sub
[\code]
 
I found this on KEA support website. NOt sure I understand it



Create macro to capture screen output to a file


--------------------------------------------------------------------------------

GOAL

Create macro to capture screen output to a file

Create macro to capture print screen to a file





--------------------------------------------------------------------------------

FACTS / ENVIRONMENT

KEA!340 5.x

KEA!420 5.x

KEA! macro language

Macro





--------------------------------------------------------------------------------

FIX

Use the macro function "CaptureSetup" to specify options for saving received data in a file.

For example:

CaptureSetup( FileName = "d:\temp\session1.txt" )
Capture = TRUE ' this property sets the object to enable or disable File Capture
* Navigation code would go here...
Capture = FALSE
 
That's some nasty code but since your willing to try so am I. Give this a spin.

Code:
Sub Main()

' Get the Attachmate Screen Object

Dim objAttachScreen As Object
Set objAttachScreen = CreateObject("EXTRA.System").ActiveSession.Screen

If (objAttachScreen is Nothing) Then
    Msgbox "Could not create the Screen object.  Possible solution open a session and try again."
    STOP
End If

' Set the default wait timeout value
    g_HostSettleTime = 500        ' milliseconds

' Name the variables
Dim MaxColumns%
Dim MaxRows%
Dim bLastPage


' This section of code contains the recorded events
    objAttachScreen.Sendkeys("vista<Ctrl+M>")    
    objAttachScreen.Sendkeys("rmd8940<Ctrl+M>")    
    objAttachScreen.Sendkeys("2BLS&RMD1.<Ctrl+M>")    
    objAttachScreen.Sendkeys("ma<Ctrl+M>")    
    objAttachScreen.Sendkeys("spo<Ctrl+M>")    
    objAttachScreen.Sendkeys("print<Ctrl+M>")    
    objAttachScreen.Sendkeys("ryan mar<Ctrl+M>")    
    objAttachScreen.Sendkeys("1<Ctrl+M>")    
    objAttachScreen.Sendkeys("<Keypad 0>;<Keypad 2><Keypad 4><Keypad 0>;<Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad Enter><Keypad Enter><Keypad Enter><Keypad Enter>")    

' Determine the size of the Screen
MaxRows%=objAttachScreen.Rows()
MaxColumns%=objAttachScreen.Cols()
    

' Copy all report screens

Do
    ReportPage$ = ReportPage$ & objAttachScreen.Area(1,1,MaxRows%,MaxColumns%,xBlock).value & chr(13)
    bLastPage = Instr(ReportPage$,"1      Performance Monitor (kc version)")
    objAttachScreen.Sendkeys("<RETURN>")   
Loop Until bLastPage

Open "c:\temp\newTest1.txt" For Output as #1
    Print # 1, ReportPage$;
    Close filenum%
End Sub

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


 
Gives me out of memory error on the string this line:
bLastPage = Instr(ReportPage$,"1 Performance Monitor (kc version)")


Know of any way to increase the memory of a string???
 
Add the line in red to the script and lets see exactly what we're grabbing. I have a couple ideas to try, but check this first.


ReportPage$ = ReportPage$ & objAttachScreen.Area(1,1,MaxRows%,MaxColumns%,xBlock).value & chr(13)
msgbox ReportPage$


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


 
This should fix the memory error for the string.
Code:
Sub Main()

' Get the Attachmate Screen Object

Dim objAttachScreen As Object
Set objAttachScreen = CreateObject("EXTRA.System").ActiveSession.Screen

If (objAttachScreen is Nothing) Then
    Msgbox "Could not create the Screen object.  Possible solution open a session and try again."
    STOP
End If

' Set the default wait timeout value
    g_HostSettleTime = 500        ' milliseconds

' Name the variables
Dim MaxColumns%
Dim MaxRows%
Dim bLastPage


' This section of code contains the recorded events
    objAttachScreen.Sendkeys("vista<Ctrl+M>")    
    objAttachScreen.Sendkeys("rmd8940<Ctrl+M>")    
    objAttachScreen.Sendkeys("2BLS&RMD1.<Ctrl+M>")    
    objAttachScreen.Sendkeys("ma<Ctrl+M>")    
    objAttachScreen.Sendkeys("spo<Ctrl+M>")    
    objAttachScreen.Sendkeys("print<Ctrl+M>")    
    objAttachScreen.Sendkeys("ryan mar<Ctrl+M>")    
    objAttachScreen.Sendkeys("1<Ctrl+M>")    
    objAttachScreen.Sendkeys("<Keypad 0>;<Keypad 2><Keypad 4><Keypad 0>;<Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad 9><Keypad Enter><Keypad Enter><Keypad Enter><Keypad Enter>")    

' Determine the size of the Screen
MaxRows%=objAttachScreen.Rows()
MaxColumns%=objAttachScreen.Cols()
    
Open "c:\temp\newTest1.txt" For Append as #1

' Copy all report screens
Do
    ReportPage$ = objAttachScreen.Area(1,1,MaxRows%,MaxColumns%,xBlock).value & chr(13)
    Print #1, ReportPage$;
    bLastPage = Instr(ReportPage$,"1      Performance Monitor (kc version)")
    objAttachScreen.Sendkeys("<RETURN>")   
Loop Until bLastPage

Close #1
End Sub

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


 
OK I have go it somewhat working. It seems to capture all the data and duplicate about 4 -6 times. Making the text file enormous!
 
Your going to have to step through the code and see where it's cycling through again. But hey we're getting closer.


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


 
OK Guys we have came a long way here. I have now got it to where it prints out really nice in agreat format, but one problem it again is only printing the first page. Any ideas?? Here is the code:
Code:
Sub Main()

' Get the Attachmate Screen Object

Dim objAttachScreen As Object
Set objAttachScreen = CreateObject("EXTRA.System").ActiveSession.Screen

If (objAttachScreen is Nothing) Then
    Msgbox "Could not create the Screen object.  Possible solution open a session and try again."
    STOP
End If

' Set the default wait timeout value
    g_HostSettleTime = 500        ' milliseconds

' Name the variables
Dim Columns%
Dim Rows%
Dim BufferSize As integer
Dim Buffer As String
Dim bLastPage
Dim NewBuffer As String
Dim CRLF As String
Dim CurPos As Integer

' This section of code contains the recorded events
	objAttachScreen.Sendkeys("vista<Ctrl+M>")	
	objAttachScreen.Sendkeys("xxxxxxx<Ctrl+M>")	
	objAttachScreen.Sendkeys("xxxxxxxxxx<Ctrl+M>")
	objAttachScreen.Sendkeys("ma<Ctrl+M>")	
	objAttachScreen.Sendkeys("SPO<Ctrl+M>")	
	objAttachScreen.Sendkeys("b<Ctrl+M>")	
	objAttachScreen.Sendkeys("RYAN MAR<Ctrl+M>")	
 
' Determine the size of the Screen
Rows%=objAttachScreen.Rows()
Columns%=objAttachScreen.Cols()
BufferSize%= Rows% * Columns%
Buffer$ = ""
NewBuffer = ""
CRLF$=Chr$(13) + Chr$(10)
CurPos% = 1

    
Open "c:\temp\newTest2.txt" For Append as #1

' Copy all report screens
Do
    
    Buffer$ = objAttachScreen.GetString(1,1, BufferSize%)
    While CurPos% < BufferSize%
        NewBuffer$ = NewBuffer$ + Mid$(Buffer$, CurPos%, Columns%) + CRLF$
        CurPos% = Curpos% + Columns%
    Wend
    Buffer$=NewBuffer$ 
    Print #1, Buffer$
    bLastPage = Instr(ReportPage$,"|TOP|")
    ScreenBuffer$ = ""
    Buffer$ = ""
    objAttachScreen.Sendkeys("<PF1>")
    objAttachScreen.Sendkeys("<DOWN>")  
Loop Until bLastPage
objAttachScreen.Sendkeys("<PF1>")
objAttachScreen.Sendkeys("E")
objAttachScreen.Sendkeys("<Ctrl+M>")
objAttachScreen.Sendkeys("<Ctrl+M>")


Close #1
End Sub
[\code]
 
OK it keeps appending the first screen over and over and over hundfres of times. It is in the Do loop that this is occuring. When I take out the While...Wend loop it prints each screen, but not properly laying it out. If I add the While loop it prints the first screen only but lays out perfect. Couple of weird things are happening.
1. At first the Rows and Coulmn Variables are showing 36 row and 80 columns, but when it gets to the buffer and before I step through it to capture the screen , it changes to Rows = 524216 & Columns = 188743760?? Not sure why this is happening.
2. The buffer size initally says 2880 and then increase in the while loop everytime it hits the CurPos% line it increases the BufferSize??

 
I GOT IT!!!!!! PROJECT IS COMPLETED!!!! Here is the code for anyone that may be interested in capturing multiple screens and it saving it to a file with a nice output.

Code:
'Global Variables
Global CapBuffer As Variant
Global CapBuffSize As Long

Sub Main()

' Get the Attachmate Screen Object

Dim objAttachScreen As Object
Set objAttachScreen = CreateObject("EXTRA.System").ActiveSession.Screen

If (objAttachScreen is Nothing) Then
    Msgbox "Could not create the Screen object.  Possible solution open a session and try again."
    STOP
End If

' Set the default wait timeout value
    g_HostSettleTime = 2500        ' milliseconds

' Name the variables
Dim Columns%
Dim Rows%
Dim BufferSize As integer
Dim Buffer As String
Dim bLastPage
Dim NewBuffer As String
Dim CRLF As String
Dim CurPos As Integer

' This section of code contains the recorded events	
        objAttachScreen.Sendkeys("vista<Ctrl+M>")	
	objAttachScreen.Sendkeys("rmd8940<Ctrl+M>")	
	objAttachScreen.Sendkeys("2BLS&RMD1.<Ctrl+M>")
	objAttachScreen.Sendkeys("ma<Ctrl+M>")	
	objAttachScreen.Sendkeys("SPO<Ctrl+M>")	
	objAttachScreen.Sendkeys("b<Ctrl+M>")	
	objAttachScreen.Sendkeys("RYAN MAR<Ctrl+M>")	
 
' Determine the size of the Screen
Rows%=objAttachScreen.Rows()
Columns%=objAttachScreen.Cols()
BufferSize%= Rows% * Columns%
Buffer$ = ""
NewBuffer = ""
CRLF$=Chr$(13) + Chr$(10)
CurPos% = 1
CapBuffer = ""
CapBuffSize& = 0
    
Open "c:\temp\newTest2.txt" For Append as #1

' Copy all report screens
Do
    objAttachScreen.WaitHostQuiet(g_HostSettleTime)
    Buffer$ = Buffer$ & objAttachScreen.GetString(1,1, BufferSize%)
    While CurPos% < BufferSize%
        NewBuffer$ = NewBuffer$ + Mid$(Buffer$, CurPos%, Columns%) + CRLF$
        CurPos% = Curpos% + Columns%
    Wend
    CurPos% =1
    Buffer$=NewBuffer$ 
    Write #1, Buffer$
    bLastPage = Instr(Buffer$,"|TOP|")
    NewBuffer$ = ""
    Buffer$ = ""
    objAttachScreen.Sendkeys("<PF1>")
    objAttachScreen.Sendkeys("<DOWN>")  
Loop Until bLastPage
objAttachScreen.Sendkeys("<PF1>")
objAttachScreen.Sendkeys("E")
objAttachScreen.Sendkeys("<Ctrl+M>")
objAttachScreen.Sendkeys("<Ctrl+M>")


Close #1
End Sub

Note the wait time is set to be 2.5 seconds as my session will not capture a screen to the buffer faster than every 2 seconds.
 
HOLD ON....Maybe one more issue. HOw about the objAttachScreen.Connected = True

I seem to not be able to get that to work???
 
Try this for the connected bit.
Code:
Set objAttachSession = CreateObject("EXTRA.System").ActiveSession
objAttachSession.Connected = True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top