×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Run a session for macro and another

Run a session for macro and another

Run a session for macro and another

(OP)
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

RE: Run a session for macro and another

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
What I Need it to do it stay on the session it's was executed on...

any ideas??

RE: Run a session for macro and another

Forever? Until you close the emulator?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
Untill the macro finishes

RE: Run a session for macro and another

Then your last post makes no sense!

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
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

RE: Run a session for macro and another

So, I don't understand the question with regard to this new information.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

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

RE: Run a session for macro and another

...which is why I posted

System.Sessions(1)

Referring to the first session opened.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
Yeah that doesn't work. Nice try though skip

Remy - would it be system.sess1?

RE: Run a session for macro and another

"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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
Don't worry about it, skip.

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

RE: Run a session for macro and another

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.

RE: Run a session for macro and another

(OP)
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.

RE: Run a session for macro and another

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
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?

RE: Run a session for macro and another

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)

' 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."

RE: Run a session for macro and another

...and the System object had been previously Set?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
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

RE: Run a session for macro and another

Well you have an ambiguity in your code ...

CODE

Set Sessions = System.Sessions 

I'd use some other object variable than Sessions.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
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

RE: Run a session for macro and another

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

RE: Run a session for macro and another

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Run a session for macro and another

(OP)
Ok so I made breakthrough this morning

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


Works like a charm

Thanks for everyone's help

RE: Run a session for macro and another

Great!

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close