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!

Copy Scrolling Data To .txt File

Status
Not open for further replies.

vzdog

Technical User
Apr 8, 2008
33
I have a macro that sends a command to a host session, works fine...Problem is I need to capture the response in to a .txt file, replacing the current contents with the new info. Here is my code so far. It runs and sends the command, but it does not call the file or if it does, does not capture the data.

Just to calrify, the lines of data could be very long 20k or more easily.

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
' 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)
    

    Sess0.Screen.Sendkeys("NE-LOCATION-REPORT F *K13 ALL ALL SUMMARY ALL ^<Ctrl+M>")   
    Sess0.Screen.WaitHostQuiet(g_HostSettleTime) 
Set Sess0=System.ActiveSession
Set MyScreen=Sess0.Screen

FileIn=FreeFile
'Takes a "snapshot" of current screen and stores it in variable Screenbuf$
MaxRows%=Sess0.Screen.Rows()
MaxColumns%=Sess0.Screen.Cols()
Screenbuf$=""
linebuf$=Space$(MaxColumns%)


filenum%=Freefile
FileName$ = "E:\Network Elements\NE Summary.txt"
Open FileName$ for append as filenum%

For row%=1 to MaxRows%
    linebuf$=Sess0.Screen.Area(row%,1,row%,MaxColumns%,xBlock)
    Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
Next
Write # filenum%,""
Close filenum%

End Sub

What am i missing or doing wrong?
thanks in advance..
 
Surely someone knows how to accomplish this?
 
vzdog,

You never actually write anything to the file with this code.

Try this after your loop that reads the screen:

Code:
fn = freefile
FileName$ = "E:\Network Elements\NE Summary.txt"
open Filename for output as fn
print #fn, Screenbuf$
close #fn

Note that I opened Filename for output rather than for append, because you said you wanted to replace the existing text in the file. (Unless I misunderstood you.)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top