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!

Run a session for macro and another

Status
Not open for further replies.

Rambonaotr

Programmer
Aug 20, 2015
13
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
 
I would need to change this?

' 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 = 1700

If (Sessions is Nothing) Then
Msgbox "Could not create the Sessions collection object. Stopping macro playback."
STOP
End If
 
Well you have an ambiguity in your code ...
Code:
Set Sessions = System.Sessions

I'd use some other object variable than Sessions.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
ok,I will work on it on my end and i'll report if I can get it to work

If you find anything on your end I would sure appreciate the help, getting close to the deadline.


anyway I appreciate the time, looks like you put a lot of time in on this site
 
Rambonaotr,
I may have misunderstood your requirements

You have several open sessions and you are evoking the macro from
let's say session 1.
does the macro go to session 2 or session 3 to do anything?

if you only want the macro to run on session 1, then
as I've said earlier, this would be the problem
Code:
Set Sess0 = System.ActiveSession
.

From my past experience, the ActiveSession is the session that is called last or clicked on.
So for the other screens, you can try something like this
Code:
Dim Sess1 as Object, Sess2 as Object
Set Sess1 = System.ActiveSession
Set Sess2 = System.ActiveSession

so your code
Code:
Sess0.Screen.Sendkeys("<Pf2>")
should run on Sess0 and not Sess1 or Sess2

 
The OP has ONE procedure that runs when a session is activated, it seems.

So the question is how can you identify the FIRST session in order to have it execute the necessary code for it and not not execute that code for any other session.

So it would seem to me that Sess0, Sess1, etc is a meaningless exersize, when you can identify the first session in the Sessions collection.

I almost ALWAYS code my Attachmate procedures in Excel VBA, which give me many extra benefits over Extra VB, like being able to BREAK the code and examine an object variable by drilling down using the Watch Window feature in the VBA Editor. So one of the things I'd try to discover is what's in the System.Sessions collection at the time that you get your message.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Ok so I made breakthrough this morning

Set Sess0 = System.Sessions.Item("Enterfilenameofthefileyouwantittorunon.rd3x")


Works like a charm

Thanks for everyone's help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top