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

Run a session for macro and another

Status
Not open for further replies.

Rambonaotr

Programmer
Aug 20, 2015
13
0
0
CA
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
 
Hi,

What can you identify that distinguishes the sessions?

Your "primary" session ought to be the FIRST session in the Sessions collection: System.Sessions(1), not System.ActiveSession!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
What I Need it to do it stay on the session it's was executed on...

any ideas??
 
Forever? Until you close the emulator?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Then your last post makes no sense!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
OK let me clarify

When the macro is running, it stays running on that session untill complete

Even when a new session has been opened thus becoming the active session
 
So, I don't understand the question with regard to this new information.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
this should be the problem
Code:
Set Sess0 = System.ActiveSession

for each session that you open, iterate, Sess0, Sess1, Sess2.
this will differentiate each of the sessions.
so if your macro refers to sess0, it will only work on that session
 
...which is why I posted

System.Sessions(1)

Referring to the first session opened.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Yeah that doesn't work. Nice try though skip

Remy - would it be system.sess1?
 
Doesn't work" doesn't work.

What do you mean by "doesn't work?" Please describe what you observed to come to this conclusion.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Don't worry about it, skip.

You may consider this one case closed. Thank you for your efforts
 
Rambonaotr,

what Skip posted is correct. if you found a solution, it would be nice if you would post it so that others can make use of it in the future.
 
hey Guys,

I thought skip had it, I thought it was working fine with System.Sessions(1) but then it happened again

So if I start my macro in one session and select the other session window, the macro starts running in that session


thanks for all your efforts but still can't find a solution...

anymore help would be greatly appreciated.
 
But that's my point. When the subsequent session runs, it is NOT Session(1), so you can Exit at that point and not execute the PROCESS that you only want for Session(1)!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Ah I see, so how do I make the first session, Session 1?

Is there a way to distinguish a session as session 1 and session 2?
 
A Session is an instance of the Sessions Collection.

Consequently the FIRST session that you open would be 1 and the next would be 2, etc.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 

' Get the necessary Session Object
Dim Sess0 As Object
Set Sess0 = System.Sessions(1)
If (Sess0 is Nothing) Then
Msgbox "Could not create the Session object. Stopping macro playback."
STOP
End If

so I changed to this and that message displays when trying to run "Could not create the Session object. Stopping macro playback.
 
...and the System object had been previously Set?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top