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

When is an Active Session not The Active Session ? 2

Status
Not open for further replies.

8pack

Technical User
Oct 27, 2002
10
GB
I wonder if anyone could shed some light on this for me ?

A little question, the answer to which eludes me to date.
(problem experienced in both 6.4 & 6.7 versions)

If I have several Attachmate sessions running concurrently and I call a macro from one of those sessions to, lets say, send some keystrokes to the Active Session (the one that the macro was called from), why does Attachmate send the key strokes to the most recently opened Session ?

I have run many tests, and have even used VB to access the Attachmate Sessions and replicate the function of the macros and every time I have concluded that.....

Set Session = System.ActiveSession

actually equates to....

Set Session = System.LatestSessionToBeOpenedRegardlessOfWhichSessionHasFocus

As, due to a number of operating restrictions, I am not able to "Hard code" the macro to a particular session I have converted all macros into VB applications and have constructed a utility that provides a constant indication of which Attachmate session shelled the VB macro routine.

Has anybody else experienced this problem or found a work around ?

Another thought, would using Session.visible = true force the ActiveSession to report correctly ? - or have I missed something totally obvious !!

Any comments would be most welcome.

Thanks

8Pack
 
I've encountered the same problem. I tried the following macro and discovered that it only writes to one session, but it does flag both sessions in Red on Win XP's status line. I'd love to get this to work so I can then write a macro to copy files from one session to another using my PC as a buffer.
----------------------
Code:
' Global variable declarations
Global g_HostSettleTime%

Sub Main()
'--------------------------------------------------------------------------------
' Get the main system object
	Dim Sessions As Object
	Dim System As Object
        Dim MyScreen 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 = 2000		' milliseconds

	OldSystemTimeout& = System.TimeoutValue
	If (g_HostSettleTime > OldSystemTimeout) Then
		System.TimeoutValue = g_HostSettleTime
	End If

' Get the necessary Session Object
	Dim Sess0 As Object
        Dim MyArea 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
	Set MyScreen = Sess0.Screen
        MyScreen.WaitHostQuiet(0)
	
' This section of code contains the recorded events
    SessionCount = System.Sessions.Count
    For i = 1 to SessionCount
	SessNames$ = SessNames$ + System.Sessions.Item(i).Name + " "
    Next
    MsgBox "The number of sessions = " + SessionCount + ". They are: " + SessNames$
Dim Sys As Object, Sess As Object
' Assumes one or more open sessions
	Set Sess = System.ActiveSession
	For i=1 to System.Sessions.Count
	   Set Sess=System.Sessions.Item(i)
	   MsgBox "Activating session " + Sess.Name + "."
	   Sess.Activate
           Sess.Visible = TRUE
'  the following sendkeys doesn't work as advertised  !!!
           MyScreen.Sendkeys(&quot;<Home>=6<enter>&quot;)	
	Next
    MyScreen.Sendkeys(&quot;<Home>&quot;)
End Sub
 
Sorry about the above. I just noticed the bug. If the final MyScreen.Sendkeys are replaced by Sess.screen.Sendkeys they work, sending the <home>=6<enter> to all sessions. This should solve your problems and mine.
 
BodyworkeR...

Hey great stuff, worked well.

I modified my code and can now write to the &quot;Active&quot; session as required !!

Thanks for your response.

 
Example:

You have 2 sessions open, hit the recrod button, and flip back and forth between the sessions, then stop the macro. It will save the code you need to determine what session would be &quot;active&quot; if you where sending keystrokes to that session.

' Get the necessary Session Objects
Dim Sess0 As Object
SessName0$ = &quot;SESSION1.EDP&quot;

Set Sess0 = Sessions.Item(SessName0$)
If Sess0 is Nothing Then
Err = MsgBox(SessName0 + &quot; is not currently open. Open it?&quot;,1)
If 1 = Err Then
Err = 0
Set Sess0 = Sessions.Open(SessName0)
If Err Then
MsgBox(&quot;Failed to open &quot; + SessName0 + &quot;. Stopping playback&quot;)
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox(&quot;Failed to open &quot; + SessName0 + &quot;. Stopping playback&quot;)
Stop
End If
End If
If Not Sess0.Visible Then Sess0.Visible = TRUE
Sess0.Screen.WaitHostQuiet(g_HostSettleTime)

Dim Sess1 As Object
SessName1$ = &quot;SESSION2.EDP&quot;

Set Sess1 = Sessions.Item(SessName1$)
If Sess1 is Nothing Then
Err = MsgBox(SessName1 + &quot; is not currently open. Open it?&quot;,1)
If 1 = Err Then
Err = 0
Set Sess1 = Sessions.Open(SessName1)
If Err Then
MsgBox(&quot;Failed to open &quot; + SessName1 + &quot;. Stopping playback&quot;)
Stop
End If
ElseIf 2 = Err Then
Stop
Else
MsgBox(&quot;Failed to open &quot; + SessName1 + &quot;. Stopping playback&quot;)
Stop
End If
End If
If Not Sess1.Visible Then Sess1.Visible = TRUE
Sess1.Screen.WaitHostQuiet(g_HostSettleTime)

Sess0.Screen.Sendkeys(&quot;your data&quot;) 'Sends your text to Session1.EDP

Sess1.Screen.Sendkeys(&quot;your data&quot;) 'Sends your text to Session2.EDP

Hope that helps
 
Thanks for that..

I have been working on another project and have not had chance to re-visit this issue but hope to get back to playing with it soon, but definately know that using .ActiveSession is not a good thing to do, it lies !!

Cheers
 
Yes, for me, ActiveSession gets the first Extra session I opened, not the session that I run the macro from. Is there a way to identify the current session?

The following macro works fine if I only have one session open. Otherwise, it copies and pastes text from the first session, even if I run it from the second session. What can I do to make it work only in the active window?
Code:
Sub Main()
	Dim Sys As Object, Sess As Object, MyScreen As Object
	'Dim MyArea As Object

	Set Sys = CreateObject("EXTRA.System")
' Assumes an open session
	Set Sess = Sys.ActiveSession
	Set MyScreen = Sess.Screen
' Gets data from upper right corner of the screen and pastes it at the current location 
        MyScreen.Select 1,73,1,80
        MyScreen.Copy
        MyScreen.Paste

End Sub
 
There is some similarity to this post:
thread99-822602

ActiveSession seems to always get either the first or last opened session (I think it's the first).

calculus
 
mdmcginn....

Its been over a year now and I have still not managed to find a reliable work-around for this 'bug' using Attachmate macro code.

For speed and reliability I had no option but to create a little VB executable monitor utility that loads on Start-up and runs continually in the background on all of my 60 users PC's which reports the current active window's 'handle'. I then converted all my main Attachmate macros that are NOT session specific and therefore not able to be 'hardcoded' to a particular session, to Visual Basic executables, each of these VB macros contains a short routine that queries the monitor utility to obtain the current active window's 'handle'. I needed to include a validation check and a short wait loop within this routine to confirm that the window identified is in fact an Attachmate application and to deal with macros that are called from a quickpad as momentarily the quickpad is technically the 'active' window.

This has worked flawlessly for 14 months now - But has required the use of additional files and 2 platforms of macros..... not ideal, but it dealt with the problem.

If you wish to go this route then I am more than willing to provide the source code details for you.

Cheers,
 
Thanks so much. I need to find out how many users (besides myself) actually have more than one session running at once. Also, I may be able to hard-code the macro somewhat. Glad to know you've found some solutions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top