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!

Tell VBA which Session to activete 1

Status
Not open for further replies.

gazza110

Technical User
Apr 14, 2004
42
GB
Hi,

I am currently using an excel VBA to activate an open session and sendkeys.

The problem I have is that the code opens the last session that was open and not the session i want.

(Here is the Code) ....
-----------------------------------------------------

Dim Sessions As Object
Dim System As Object
Set System = CreateObject("EXTRA.System")
If (System Is Nothing) Then
MsgBox "error1"
Stop
End If
Set Sessions = System.Sessions

If (Sessions Is Nothing) Then
MsgBox "error2"
Stop
End If

Dim Sess0 As Object
SessName0$ = "Dice.EDP"

Set Sess0 = System.activesession
If (Sess0 Is Nothing) Then
MsgBox "error3"
Stop
End If

If Not Sess0.Visible Then Sess0.Visible = True

Sess0.Screen.SendKeys ("Hello")

-----------------------------------------------------

The session I want to use is called "Dis" however the last session opened on the system is "MAINFRAME" and I want to sendkeys to "Dis"

Is there anyway I can tell VB to deal with "Dis" and NOT "MAINFRAME" as the ' System.activesession ' part of the code takes you to the "MAINFRAME" session as this was the last opened session.

Any help greatly appreciated.

Gaz.
 
Your problem is coming in the line:
Set Sess0 = System.activesession

the activesession is the last opened (I think).

You'll need to use the session object to find the session you want. I'm assuming that the session "Dis" is already open.

Set Sess0 = System.Sessions.Item("Dis.edp")

The sessions object has some interesting properties like count and item that will tell you how many sessions are open and what there names are. Since you're working in VBA, you can add a reference to your project that will help you a lot. From the VBA editor, choose tools>references then select Attachmate Extra!. Now you can DIM your objects as ExtraApplication, ExtraSessions and ExtraSession. This will give you all the available properties and methods to these objects.

calculus
 
Calculus, thanks for the reply, however I'm still having problems with this.

I replaced the line of code with your suggestion, however when I run the macro, I get the following error:

--------------------------------------------------
Run-time error '2147418113 (8000ffff)':

The specified session is not available
--------------------------------------------------

The sesssion is open on the system, however excel does not seem to understand this.

Any other suggestions ???

Many Thanks,
Gaz.
 
Yes, the best thing to do at this point is to see what sessions are available. I think your "Dis" is probably know as something else by the system. I suggest you loop through the sessions to see what they are named.

Code:
For Sess = 1 to Sessions.Count
rc% = Msgbox (Sessions.Item(Sess).Name & "   Index = " & Sess)
If StrComp(Sessions.Item(Sess).Name, "Extra", vbTextCompare) = 0 Then Exit For
Next Sess

Set Sess0 = System.Sessions.Item(Sess)

This will Show you the names of each session. You may also wannt to use the index of each session. I think I had to use the index number of the session when I did this. Remove the msgbox line when you get it working.

calculus
 
gazza110....

I have been doing battle with the ActiveSession issue for some time now (see thread99-477787) and it would appear you have already been pointed in the best direction by calculus, However, I have also encountered the same Runtime error you refer to when using the System.Sessions.Item object.

I have 60 users running Win2K on desktop PC's that can use both Attachmate and Excel VBA macros referencing the .Item object without any problems, but I am unable to run the same macros on 3 laptops used by the managers without obtaining the Runtime error.... Fundamentally the laptops 'appear' to have the same overall build as the desktop PC's (Win2K Etc..) - unfortunately they are provided by the company via different channels and as such I am not permitted to alter/re-build to confirm this.

I have provided clean installs of both Extra! 6.5 & 6.7 on all laptops in an attempt to identify the problem, alas I can not find out why a particular 'build' would not allow the .Item object to be used without obtaining the Runtime error.

Regretably this has not provided a solution for you, but I felt that sharing my findings may possibly assist ?

8pack
 
I got a macro to work running two different sessions using these lines of code:

Set Sess0 = System.Sessions.Item("C:\Program Files\E!PC\Sessions\Session2.edp")

Sess0.screen. 'do something'

Set Sess0 = System.Sessions.Item("C:\Program Files\E!PC\Sessions\Session3.edp")

Sess0.screen. 'do something'

It seems you have to enter the file path for Extra/Excel to recognize which session you are trying to access.

Hope this helps.

Thanks.
 

This thread is fairly old, but I'll post my solution in the event that another user is reading this for a fix.

While the following may seem simplistic, I have found it to work well for my needs.

Rather than find the exact session name, I simply have VBA cycle through all active sessions and use GetString until it finds the first open session instance with the unique Screen name needed by the VBA script in order to continue execution (although a string test against any text unique to the active page will work).

Obviously, certain details will have to be augmented for your environment:

' Evaluate open sessions to find COP877DS page
' -----------------------------------------

Dim SessionCount As Integer
Dim iCount As Integer

' Set initial session test variables
SessionCount = Sessions.Count

'Reset counter variable
iCount = 1

' Run test loop
While iCount <= SessionCount

'Gather ASI header value
Header = Sess0.Screen.GetString(2, 73, 8)
'MsgBox Sess0.Name & Chr(10) & header

'If header does not equal OP/RR header, cycle through all
'If not found, set SessionVerified to false
If Header <> "COP877DS" Then
Sessions.JumpNext
Set Sess0 = System.ActiveSession
If iCount = SessionCount Then
MsgBox "The OP/RR query screen must be open for the macro to execute. Please navigate to OP/RR and try again."
SessionVerified = False
End If
iCount = iCount + 1
Else
iCount = SessionCount + 1
SessionVerified = True
End If

Wend

'End Code
'----------------------------------------------

I hope this helps someone.

counterform
 
I have not been able to actually solve this problem, but I have learned that ActiveSession seems to be the last session to run a macro. I tried opening and closing sessions and various other experiments, but ActiveSession always seems to default to the last macro session, sometimes even when running the macro from inside the session (menu bar, toolbar, keyboard).

oddly, this problem was nonexistent in old versions of Extra! because that version of Basic relied on the short name for the session - A, B, C, etc. instead of the session ID. this allowed you to specify the session and use the same macro on different machines without much coding. Personal Client doesn't seem to recognize the short name at all.

wish there was some obvious and easy fix for this. I'm disappointed at Attachmate's lack of support.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top