Rambonaotr
Programmer
Hello,
I want to have two sessions open, I currently have 1 open (primary) and another (backup)
when I run the macro in primary and then click on the backup session the macro starts running in the backup session and doesn't work.
how can I get the macro to only run on primary??
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "\\WPG-YD-F15A\PROVOS02_SYNC$\ATTACHMATE\SESSION\SYLVAIN1.EDP"
' Date: Thursday, May 18, 2006 10:33:33
' User: provos02
'--------------------------------------------------------------------------------
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$
Declare Sub KeyA (CStation As String)
Declare Sub KeyB (CStation As String, DStation As String, Plan as String)
Declare Sub ScreenCap ()
Sub Main()
'On Error Resume Next
reset
'--------------------------------------------------------------------------------
' 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
System.timeoutvalue = 1500
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 = 1 ' 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)
Kill "c:\data\temp\IMVessel1.txt"
Kill "c:\data\temp\IMVessel2.txt"
call KeyA ("BRAINTTERON")
call KeyA ("MONTASYARPQ")
call KeyA ("CHIINTTERIL")
Beep
OETMP& = Shell("C:\Program Files\Microsoft Office\Office12\excel.exe /R C:\Users\"& Environ$("USERNAME")&"\Documents\Attachmate\Macros\IMVessel.xls", 1)
System.TimeoutValue = OldSystemTimeout
End Sub
Sub KeyA (CStation$)
call KeyB (CStation$,"FAICOVIMPNS","82")
call KeyB (CStation$,"ROBBANK BC","82")
call KeyB (CStation$,"MONTERMONPQ","82")
call KeyB (CStation$,"MONVIATERPQ","82")
call KeyB (CStation$,"HALHALTERNS","82")
call KeyB (CStation$,"STJOHIMPENB","82")
call KeyB (CStation$,"MONWHARF PQ","82")
call KeyB (CStation$,"MONRACTERPQ","82")
call KeyB (CStation$,"VANVANTERBC","82")
call KeyB (CStation$,"VANCENPIEBC","82")
call KeyB (CStation$,"FRASURIMPBC","82")
call KeyB (CStation$,"PRIRUPTERBC","82")
call KeyB (CStation$,"NEWORLEANLA","82")
'call KeyB (CStation$,"PHILADELPPA","82")
'call KeyB (CStation$,"ELIMARTE NJ","82")
call KeyB (CStation$,"FAICOVIMPNS","85")
call KeyB (CStation$,"ROBBANK BC","85")
call KeyB (CStation$,"MONTERMONPQ","85")
call KeyB (CStation$,"MONVIATERPQ","85")
call KeyB (CStation$,"HALHALTERNS","85")
call KeyB (CStation$,"STJOHIMPENB","85")
call KeyB (CStation$,"MONWHARF PQ","85")
call KeyB (CStation$,"MONRACTERPQ","85")
call KeyB (CStation$,"VANVANTERBC","85")
call KeyB (CStation$,"VANCENPIEBC","85")
call KeyB (CStation$,"FRASURIMPBC","85")
call KeyB (CStation$,"PRIRUPTERBC","85")
call KeyB (CStation$,"NEWORLEANLA","85")
'call KeyB (CStation$,"PHILADELPPA","85")
'call KeyB (CStation$,"ELIMARTE NJ","85")
call KeyB (CStation$,"FAICOVIMPNS","95")
call KeyB (CStation$,"ROBBANK BC","95")
call KeyB (CStation$,"MONTERMONPQ","95")
call KeyB (CStation$,"MONVIATERPQ","95")
call KeyB (CStation$,"HALHALTERNS","95")
call KeyB (CStation$,"STJOHIMPENB","95")
call KeyB (CStation$,"MONWHARF PQ","95")
call KeyB (CStation$,"MONRACTERPQ","95")
call KeyB (CStation$,"VANVANTERBC","95")
call KeyB (CStation$,"VANCENPIEBC","95")
call KeyB (CStation$,"FRASURIMPBC","95")
call KeyB (CStation$,"PRIRUPTERBC","95")
call KeyB (CStation$,"NEWORLEANLA","95")
'call KeyB (CStation$,"PHILADELPPA","95")
'call KeyB (CStation$,"ELIMARTE NJ","95")
call KeyB (CStation$,"VANINTTERBC","87")
'call KeyB (CStation$,"PHILADELPPA","87")
call KeyB (CStation$,"VANVANTERBC","87")
call KeyB (CStation$,"VANCENPIEBC","87")
call KeyB (CStation$,"FRASURIMPBC","87")
'call KeyB (CStation$,"ELIMARTE NJ","87")
End Sub
Sub KeyB (CStation$, DStation$, Plan$)
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system 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("<Pf2>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>traf<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>y<Tab><Tab><Tab>"+CStation$+"<Tab><Tab><Tab>"+DStation$+"<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>"+Plan$+"<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>N<ENTER>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>1<Tab><Tab><Tab><Tab><Tab><Tab><Tab>2<Tab><Tab><Tab>3<Tab><Tab><Tab>4<Tab><Tab><Tab><Tab>6<Tab>7<Tab><Tab><Tab><Tab><Tab>8<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>9<Tab><Tab><Tab><Tab><Tab><Tab>10<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab><Tab>11<Pf5>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Call ScreenCap ()
End Sub
Sub ScreenCap()
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system 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)
' Name the variables
Dim rc%
Dim MaxColumn%
Dim row%
Dim MaxRows%
Dim filenumA%
Dim filenumB%
Dim Screenbuf$
Dim linebuf$
Dim FileName$
Dim Msg$
Dim InfLoop%
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%)
linebuf$=Sess0.Screen.Area(1,3,1,6,xBlock)
if Trim(linebuf$) <> "===>" then Exit Sub
filenumA%=Freefile
FileNameA$ = "c:\data\temp\IMVessel1.txt"
Open FileNameA$ for append as filenumA%
filenumB%=Freefile
FileNameB$ = "c:\data\temp\IMVessel2.txt"
Open FileNameB$ for append as filenumB%
For InfLoop%=1 to 100
linebuf$=Sess0.Screen.Area(1,60,1,64,xBlock)
if not right(Trim(linebuf$),1) = "1" then Exit For
For row%=2 to 21
linebuf$=Sess0.Screen.Area(row%,1,row%,MaxColumns%,xBlock)
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
Next
msg$ = Chr$(13)+Chr$(10)+Screenbuf$
Write # filenumA%,msg$
Screenbuf$=""
Sess0.Screen.Sendkeys("<Pf11>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
For row%=2 to 21
linebuf$=Sess0.Screen.Area(row%,1,row%,MaxColumns%,xBlock)
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
Next
msg$ = Chr$(13)+Chr$(10)+Screenbuf$
Write # filenumB%,msg$
Screenbuf$=""
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Sess0.Screen.Sendkeys("<Pf10><Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Next
Close filenumA%
Close filenumB%
End Sub
I want to have two sessions open, I currently have 1 open (primary) and another (backup)
when I run the macro in primary and then click on the backup session the macro starts running in the backup session and doesn't work.
how can I get the macro to only run on primary??
'--------------------------------------------------------------------------------
' This macro was created by the Macro Recorder.
' Session Document: "\\WPG-YD-F15A\PROVOS02_SYNC$\ATTACHMATE\SESSION\SYLVAIN1.EDP"
' Date: Thursday, May 18, 2006 10:33:33
' User: provos02
'--------------------------------------------------------------------------------
' Global variable declarations
Global g_HostSettleTime%
Global g_szPassword$
Declare Sub KeyA (CStation As String)
Declare Sub KeyB (CStation As String, DStation As String, Plan as String)
Declare Sub ScreenCap ()
Sub Main()
'On Error Resume Next
reset
'--------------------------------------------------------------------------------
' 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
System.timeoutvalue = 1500
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 = 1 ' 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)
Kill "c:\data\temp\IMVessel1.txt"
Kill "c:\data\temp\IMVessel2.txt"
call KeyA ("BRAINTTERON")
call KeyA ("MONTASYARPQ")
call KeyA ("CHIINTTERIL")
Beep
OETMP& = Shell("C:\Program Files\Microsoft Office\Office12\excel.exe /R C:\Users\"& Environ$("USERNAME")&"\Documents\Attachmate\Macros\IMVessel.xls", 1)
System.TimeoutValue = OldSystemTimeout
End Sub
Sub KeyA (CStation$)
call KeyB (CStation$,"FAICOVIMPNS","82")
call KeyB (CStation$,"ROBBANK BC","82")
call KeyB (CStation$,"MONTERMONPQ","82")
call KeyB (CStation$,"MONVIATERPQ","82")
call KeyB (CStation$,"HALHALTERNS","82")
call KeyB (CStation$,"STJOHIMPENB","82")
call KeyB (CStation$,"MONWHARF PQ","82")
call KeyB (CStation$,"MONRACTERPQ","82")
call KeyB (CStation$,"VANVANTERBC","82")
call KeyB (CStation$,"VANCENPIEBC","82")
call KeyB (CStation$,"FRASURIMPBC","82")
call KeyB (CStation$,"PRIRUPTERBC","82")
call KeyB (CStation$,"NEWORLEANLA","82")
'call KeyB (CStation$,"PHILADELPPA","82")
'call KeyB (CStation$,"ELIMARTE NJ","82")
call KeyB (CStation$,"FAICOVIMPNS","85")
call KeyB (CStation$,"ROBBANK BC","85")
call KeyB (CStation$,"MONTERMONPQ","85")
call KeyB (CStation$,"MONVIATERPQ","85")
call KeyB (CStation$,"HALHALTERNS","85")
call KeyB (CStation$,"STJOHIMPENB","85")
call KeyB (CStation$,"MONWHARF PQ","85")
call KeyB (CStation$,"MONRACTERPQ","85")
call KeyB (CStation$,"VANVANTERBC","85")
call KeyB (CStation$,"VANCENPIEBC","85")
call KeyB (CStation$,"FRASURIMPBC","85")
call KeyB (CStation$,"PRIRUPTERBC","85")
call KeyB (CStation$,"NEWORLEANLA","85")
'call KeyB (CStation$,"PHILADELPPA","85")
'call KeyB (CStation$,"ELIMARTE NJ","85")
call KeyB (CStation$,"FAICOVIMPNS","95")
call KeyB (CStation$,"ROBBANK BC","95")
call KeyB (CStation$,"MONTERMONPQ","95")
call KeyB (CStation$,"MONVIATERPQ","95")
call KeyB (CStation$,"HALHALTERNS","95")
call KeyB (CStation$,"STJOHIMPENB","95")
call KeyB (CStation$,"MONWHARF PQ","95")
call KeyB (CStation$,"MONRACTERPQ","95")
call KeyB (CStation$,"VANVANTERBC","95")
call KeyB (CStation$,"VANCENPIEBC","95")
call KeyB (CStation$,"FRASURIMPBC","95")
call KeyB (CStation$,"PRIRUPTERBC","95")
call KeyB (CStation$,"NEWORLEANLA","95")
'call KeyB (CStation$,"PHILADELPPA","95")
'call KeyB (CStation$,"ELIMARTE NJ","95")
call KeyB (CStation$,"VANINTTERBC","87")
'call KeyB (CStation$,"PHILADELPPA","87")
call KeyB (CStation$,"VANVANTERBC","87")
call KeyB (CStation$,"VANCENPIEBC","87")
call KeyB (CStation$,"FRASURIMPBC","87")
'call KeyB (CStation$,"ELIMARTE NJ","87")
End Sub
Sub KeyB (CStation$, DStation$, Plan$)
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system 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("<Pf2>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>traf<Enter>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>y<Tab><Tab><Tab>"+CStation$+"<Tab><Tab><Tab>"+DStation$+"<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>"+Plan$+"<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>N<ENTER>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab>1<Tab><Tab><Tab><Tab><Tab><Tab><Tab>2<Tab><Tab><Tab>3<Tab><Tab><Tab>4<Tab><Tab><Tab><Tab>6<Tab>7<Tab><Tab><Tab><Tab><Tab>8<Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab><Tab>9<Tab><Tab><Tab><Tab><Tab><Tab>10<Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Sess0.Screen.Sendkeys("<Tab><Tab><Tab>11<Pf5>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Call ScreenCap ()
End Sub
Sub ScreenCap()
Dim System As Object
Set System = CreateObject("EXTRA.System") ' Gets the system 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)
' Name the variables
Dim rc%
Dim MaxColumn%
Dim row%
Dim MaxRows%
Dim filenumA%
Dim filenumB%
Dim Screenbuf$
Dim linebuf$
Dim FileName$
Dim Msg$
Dim InfLoop%
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%)
linebuf$=Sess0.Screen.Area(1,3,1,6,xBlock)
if Trim(linebuf$) <> "===>" then Exit Sub
filenumA%=Freefile
FileNameA$ = "c:\data\temp\IMVessel1.txt"
Open FileNameA$ for append as filenumA%
filenumB%=Freefile
FileNameB$ = "c:\data\temp\IMVessel2.txt"
Open FileNameB$ for append as filenumB%
For InfLoop%=1 to 100
linebuf$=Sess0.Screen.Area(1,60,1,64,xBlock)
if not right(Trim(linebuf$),1) = "1" then Exit For
For row%=2 to 21
linebuf$=Sess0.Screen.Area(row%,1,row%,MaxColumns%,xBlock)
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
Next
msg$ = Chr$(13)+Chr$(10)+Screenbuf$
Write # filenumA%,msg$
Screenbuf$=""
Sess0.Screen.Sendkeys("<Pf11>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
For row%=2 to 21
linebuf$=Sess0.Screen.Area(row%,1,row%,MaxColumns%,xBlock)
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Screenbuf$=Screenbuf$+linebuf$+Chr$(13)+Chr$(10)
Next
msg$ = Chr$(13)+Chr$(10)+Screenbuf$
Write # filenumB%,msg$
Screenbuf$=""
if Trim(linebuf$) = ".... End of Report ...." then Exit For
if Trim(linebuf$) = ".... END OF REPORT ...." then Exit For
Sess0.Screen.Sendkeys("<Pf10><Pf8>")
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)
Next
Close filenumA%
Close filenumB%
End Sub