Tell VBA which Session to activete
Tell VBA which Session to activete
(OP)
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.
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.
RE: Tell VBA which Session to activete
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
RE: Tell VBA which Session to activete
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.
RE: Tell VBA which Session to activete
CODE
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
RE: Tell VBA which Session to activete
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
RE: Tell VBA which Session to activete
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.
RE: Tell VBA which Session to activete
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
RE: Tell VBA which Session to activete
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.